如何在java中创建多个下拉框?我想在这些代码行之后添加另一个下拉框

30byixjq  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(396)
  1. JFrame frame = new JFrame("Recipes");
  2. frame.setVisible(true);
  3. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  4. frame.setSize(500, 500);
  5. frame.setLocation(430, 100);
  6. JPanel panel = new JPanel();
  7. frame.add(panel);
  8. JLabel lbl = new JLabel("Select time taken");
  9. lbl.setVisible(true);
  10. panel.add(lbl);
  11. String[] choices = { "10 MINS","15 MINS", "20 MINS","25 MINS","30 MINS"};
  12. final JComboBox<String> cb = new JComboBox<String>(choices);
  13. cb.setVisible(true);
  14. panel.add(cb);
  15. JButton btn = new JButton("OK");
  16. panel.add(btn);`

我不知道在这之后要添加什么,我尝试添加另一个标签和组合框,但没有成功

acruukt9

acruukt91#

确保 frame.setVisible(true); 在最后一行

  1. import javax.swing.JButton;
  2. import javax.swing.JComboBox;
  3. import javax.swing.JFrame;
  4. import javax.swing.JLabel;
  5. import javax.swing.JPanel;
  6. public class Test01 {
  7. public static void main(String[] args) {
  8. // TODO Auto-generated method stub
  9. JFrame frame = new JFrame("Recipes");
  10. //frame.setVisible(true);
  11. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  12. frame.setSize(500, 500);
  13. frame.setLocation(430, 100);
  14. JPanel panel = new JPanel();
  15. frame.add(panel);
  16. JLabel lbl = new JLabel("Select time taken");
  17. lbl.setVisible(true);
  18. panel.add(lbl);
  19. String[] choices = { "10 MINS","15 MINS", "20 MINS","25 MINS","30 MINS"};
  20. final JComboBox<String> cb = new JComboBox<String>(choices);
  21. cb.setVisible(true);
  22. panel.add(cb);
  23. JButton btn = new JButton("OK");
  24. panel.add(btn);
  25. frame.setVisible(true);
  26. }
  27. }
展开查看全部

相关问题