用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

创建一个JTabbedPane面板,为每一个标签设置一个名称

2015-02-11 作者: java源代码大全举报

[java]代码库

package three;

//这段程序主要是创建一个JTabbedPane面板,为每一个标签设置一个名称
import javax.swing.*;
import java.awt.*;
public class test7
{
 public static void main(String[] args)
 {
  try
{//显示外观风格
	  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e){
	e.printStackTrace();
} 
  JFrame frame = new JFrame ("资金状况");
  frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
  frame.setVisible (true);//默认为false
  JTabbedPane tp=new JTabbedPane();//创建一个选项卡容器,将之添加到顶层容器内
  frame.setContentPane(tp);
  JPanel panel1 = new JPanel ();
  JPanel panel2 = new JPanel ();
  JPanel panel3 = new JPanel ();
  JPanel panel4 = new JPanel ();
  JPanel panel5 = new JPanel ();
  tp.addTab("panel1", panel1); //添加选项卡容器,并且设置其中每个选项卡的标签以及其是否可启用
  tp.setEnabledAt(0,true);
  tp.setTitleAt(0,"个人收入状况");
  
  tp.addTab ("panel2", panel2);
  tp.setEnabledAt (1, true);
  tp.setTitleAt (1,"工资");
  
  tp.addTab ("panel3", panel3);
  tp.setEnabledAt (2, true);
  tp.setTitleAt (2,"奖金");
  
  tp.addTab ("panel4", panel4);
  tp.setEnabledAt(3,true);
  tp.setTitleAt(3,"津贴");
  
  tp.addTab ("panel5", panel5);
  tp.setEnabledAt(4,true);
  tp.setTitleAt(4,"社保");
  
///设置其大小以及其选项卡的位置方向
  tp.setPreferredSize (new Dimension (500,200));
 tp.setTabPlacement (JTabbedPane.TOP);
///设置选项卡在容器内的显示形式
  tp.setTabLayoutPolicy (JTabbedPane.SCROLL_TAB_LAYOUT);
  frame.pack();
 }
}

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at javax.swing.plaf.basic.BasicTabbedPaneUI.rotateInsets(BasicTabbedPaneUI.java:1920)
    at javax.swing.plaf.basic.BasicTabbedPaneUI.getTabAreaInsets(BasicTabbedPaneUI.java:1579)
    at javax.swing.plaf.basic.BasicTabbedPaneUI$TabbedPaneScrollLayout.calculateTabRects(BasicTabbedPaneUI.java:2792)
    at javax.swing.plaf.basic.BasicTabbedPaneUI$TabbedPaneLayout.calculateLayoutInfo(BasicTabbedPaneUI.java:2263)
    at javax.swing.plaf.basic.BasicTabbedPaneUI$TabbedPaneScrollLayout.layoutContainer(BasicTabbedPaneUI.java:2596)
    at java.awt.Container.layout(Container.java:1401)
    at java.awt.Container.doLayout(Container.java:1390)
    at java.awt.Container.validateTree(Container.java:1473)
    at java.awt.Container.validateTree(Container.java:1480)
    at java.awt.Container.validateTree(Container.java:1480)
    at java.awt.Container.validate(Container.java:1448)
    at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:379)
    at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:109)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)


初次接触swing 。。完全看不懂这个异常从哪里出来的。。

求讲解。~//源代码片段来自云代码http://yuncode.net
			


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...