正文

JTabbedPane用法2005-09-22 17:18:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/hurongliang/5105.html

分享到:

import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.BoxLayout;
import javax.swing.JTabbedPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.UIManager;

class TabPane extends JTabbedPane
{
 JPanel panel1, panel2, panel3, panel4, panel5;
 
 public TabPane ()
 {
  //super (a, b);
  panel1 = new JPanel ();
  panel1.add(new JButton());
  panel2 = new JPanel (new BorderLayout());
  panel3 = new JPanel (true);
  panel4 = new JPanel (new GridLayout(2,3));
  panel5 = new JPanel (new FlowLayout(FlowLayout.LEFT, 1, 0));
  //以上是JPanel的四种构造方法
  //窗体布局器有四种设置:
  //new BorderLayout () or new BorderLayout (int hgap, int vgap)
  //new GridLayout () or new GridLayout (int rows, int cols) new GridLayout (int rows, int cols, int hgap, int vgap)
  //new FlowLayout () or new FlowLayout (int align) or new FlowLayout (int align, int hgap, int vgap)
  //new BoxLayout (Container target, int axis)
  
  //public JTabbedPane (int tabPlacement, int tabLayoutPolicy)
  //tabPlacement:JTabbedPane.TOP, JTabbedPane.BOTTOM, JTabbedPane.LEFT, or JTabbedPane.RIGHT.
  //ltabLayoutPolicy:JTabbedPane.WRAP_TAB_LAYOUT or JTabbedPane.SCROLL_TAB_LAYOUT.
  //其他两种JTabbedPane的构造方法:
  //JTabbedPane ()
  //JTabbedPane (int tabPlacement)
  add (panel1, 0);
  setBackgroundAt (0, Color.cyan);
  setForegroundAt (0,Color.red);

  add (panel2, this , 1);
  setEnabledAt (1, false);
  setTitleAt (1,"panel one");

  addTab ("panel3", panel3);
  setToolTipTextAt (2, "ToolTip3");

  addTab ("panel4", new ImageIcon("QQ.png"), panel4, "ToolTip4");
  
  addTab ("panel5", panel5);
  
  setPreferredSize (new Dimension (500,200));
  setTabPlacement (JTabbedPane.BOTTOM);//设置标签的位置
  setTabLayoutPolicy (JTabbedPane.SCROLL_TAB_LAYOUT);
 }
}

public class JTabbedPaneDemo
{
 public static void main(String[] args)
 {
  try{UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}catch(Exception e){}//显示风格
  TabPane tabPane = new TabPane ();
  JFrame frame = new JFrame ("JTabbedPaneDemo");
  frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
  frame.setVisible (true);//默认为false
  frame.setContentPane(tabPane);
  frame.pack();
 }
}
  
  
  
  

阅读(12009) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册