java中切换选项卡是什么啊?
java中选项卡是什么控啊?在VS中叫TabControl在JAVA中叫什么啊??能不能给个实际的用法啊?...
java中选项卡是什么控啊 ?
在VS中 叫 TabControl
在JAVA 中 叫什么啊??
能不能给个实际的用法啊? 展开
在VS中 叫 TabControl
在JAVA 中 叫什么啊??
能不能给个实际的用法啊? 展开
2个回答
展开全部
swing里
JTabbedPane
下面一个例子:
其中private JTabbedPane tabs = new JTabbedPane();这句是实例化一个选项卡tabs,
tabs.addTab(colorNames[i],panel); 这句是向tabs里加一个页面。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
public class TabbedPaneDemo extends JFrame {
private String[] colorNames = {
"red", "blue", "green", "black",
"yellow", "pink", "white"};
private Color[] colors = {
Color.RED, Color.BLUE, Color.GREEN, Color.BLACK,
Color.YELLOW, Color.PINK, Color.WHITE};
private JTabbedPane tabs = new JTabbedPane();
//private JTabbedPane tabs = new JTabbedPane(JTabbedPane.BOTTOM,
// JTabbedPane.SCROLL_TAB_LAYOUT );
private JTextField txt = new JTextField(20);
public TabbedPaneDemo(String title) {
super(title);
for(int i = 0; i < colors.length; i++){
JPanel panel=new JPanel();
panel.setBackground(colors[i]);
tabs.addTab(colorNames[i],panel); //加入一个页面
}
tabs.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
txt.setText("Tab selected: " +
tabs.getSelectedIndex());
}
});
Container contentPane = getContentPane();
contentPane.add(BorderLayout.SOUTH, txt);
contentPane.add(tabs);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public static void main(String[] args) {
new TabbedPaneDemo("Hello");
}
}
JTabbedPane
下面一个例子:
其中private JTabbedPane tabs = new JTabbedPane();这句是实例化一个选项卡tabs,
tabs.addTab(colorNames[i],panel); 这句是向tabs里加一个页面。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
public class TabbedPaneDemo extends JFrame {
private String[] colorNames = {
"red", "blue", "green", "black",
"yellow", "pink", "white"};
private Color[] colors = {
Color.RED, Color.BLUE, Color.GREEN, Color.BLACK,
Color.YELLOW, Color.PINK, Color.WHITE};
private JTabbedPane tabs = new JTabbedPane();
//private JTabbedPane tabs = new JTabbedPane(JTabbedPane.BOTTOM,
// JTabbedPane.SCROLL_TAB_LAYOUT );
private JTextField txt = new JTextField(20);
public TabbedPaneDemo(String title) {
super(title);
for(int i = 0; i < colors.length; i++){
JPanel panel=new JPanel();
panel.setBackground(colors[i]);
tabs.addTab(colorNames[i],panel); //加入一个页面
}
tabs.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
txt.setText("Tab selected: " +
tabs.getSelectedIndex());
}
});
Container contentPane = getContentPane();
contentPane.add(BorderLayout.SOUTH, txt);
contentPane.add(tabs);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public static void main(String[] args) {
new TabbedPaneDemo("Hello");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询