📜  Java Swing-JTabbedPane

📅  最后修改于: 2020-09-30 06:38:48             🧑  作者: Mango

Java JTabbedPane

通过单击带有给定标题或图标的选项卡,可以使用JTabbedPane类在一组组件之间切换。它继承了JComponent类。

JTabbedPane类声明

我们来看一下javax.swing.JTabbedPane类的声明。

public class JTabbedPane extends JComponent implements Serializable, Accessible, SwingConstants

常用的构造函数:

Constructor Description
JTabbedPane() Creates an empty TabbedPane with a default tab placement of JTabbedPane.Top.
JTabbedPane(int tabPlacement) Creates an empty TabbedPane with a specified tab placement.
JTabbedPane(int tabPlacement, int tabLayoutPolicy) Creates an empty TabbedPane with a specified tab placement and tab layout policy.

Java JTabbedPane示例

import javax.swing.*;
public class TabbedPaneExample {
JFrame f;
TabbedPaneExample(){
f=new JFrame();
JTextArea ta=new JTextArea(200,200);
JPanel p1=new JPanel();
p1.add(ta);
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JTabbedPane tp=new JTabbedPane();
tp.setBounds(50,50,200,200);
tp.add("main",p1);
tp.add("visit",p2);
tp.add("help",p3);
f.add(tp);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String[] args) {
new TabbedPaneExample();
}}

输出: