展开全部
参考下面的代码:
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Test {
public static void main(String[] args) {
JComboBox b1=new JComboBox(new String[]{"AAA","BBB","CCC","DDD"});
JComboBox b2=new JComboBox(b1.getModel());
JFrame f=new JFrame();
f.setSize(300,300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p=new JPanel(new BorderLayout());
p.add(b1,BorderLayout.NORTH);
p.add(b2,BorderLayout.SOUTH);
f.add(p);
f.setVisible(true);
}
}
也就是使用相同的model
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Test {
public static void main(String[] args) {
JComboBox b1=new JComboBox(new String[]{"AAA","BBB","CCC","DDD"});
JComboBox b2=new JComboBox(b1.getModel());
JFrame f=new JFrame();
f.setSize(300,300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p=new JPanel(new BorderLayout());
p.add(b1,BorderLayout.NORTH);
p.add(b2,BorderLayout.SOUTH);
f.add(p);
f.setVisible(true);
}
}
也就是使用相同的model
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询