我正在尝试在一个选项卡中创建一个组合框,而在另一个选项卡中创建一个按钮.. 但我面临的问题是我看不到组合框的项目..请帮助.. 还告诉我如何在另一个选项卡中导入图像..
import java.awt.*;
import java.awt.event.*;
//import java.swing.*;
import java.util.*;
import javax.swing.*;
class c_box extends JFrame {
public static void main(String args[])
{
JFrame frame = new JFrame("Combo Box Demo");
Panel p=new Panel();
// GridLayout gl=new GridLayout(1, 3, 30, 30);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 800);
Vector comboBoxItems=new Vector();
Vector comboBoxItems2=new Vector();
Vector comboBoxItems3=new Vector();
comboBoxItems.add("A");
comboBoxItems.add("B");
comboBoxItems.add("C");
comboBoxItems.add("D");
comboBoxItems.add("E");
comboBoxItems2.add("1");
comboBoxItems2.add("2");
comboBoxItems2.add("3");
comboBoxItems2.add("4");
comboBoxItems3.add("1a");
comboBoxItems3.add("2b");
comboBoxItems3.add("3c");
comboBoxItems3.add("4d");
final DefaultComboBoxModel model = new DefaultComboBoxModel(comboBoxItems);
final DefaultComboBoxModel model2 = new DefaultComboBoxModel(comboBoxItems2);
final DefaultComboBoxModel model3 = new DefaultComboBoxModel(comboBoxItems3);
JComboBox comboBox = new JComboBox(model);
JComboBox comboBox2 = new JComboBox(model2);
JComboBox comboBox3 = new JComboBox(model3);
p.add(comboBox,BorderLayout.WEST);
p.add(comboBox2);
p.add(comboBox3);
JTabbedPane tab=new JTabbedPane();
frame.add(tab, BorderLayout.CENTER);
JButton button = new JButton("Add new element in combo box");
tab.add("tab1",p);
tab.add("tab1",button);
frame.setVisible(true);
}
}