Reputation: 25
JFrame frame = new JFrame("Recipes");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setLocation(430, 100);
JPanel panel = new JPanel();
frame.add(panel);
JLabel lbl = new JLabel("Select time taken");
lbl.setVisible(true);
panel.add(lbl);
String[] choices = { "10 MINS","15 MINS", "20 MINS","25 MINS","30 MINS"};
final JComboBox<String> cb = new JComboBox<String>(choices);
cb.setVisible(true);
panel.add(cb);
JButton btn = new JButton("OK");
panel.add(btn);`
I don't know what to add after this, I tried adding another label and combobox but it didn't work
Upvotes: 1
Views: 244
Reputation: 565
Ensure that frame.setVisible(true);
is in the last line
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Test01 {
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame frame = new JFrame("Recipes");
//frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setLocation(430, 100);
JPanel panel = new JPanel();
frame.add(panel);
JLabel lbl = new JLabel("Select time taken");
lbl.setVisible(true);
panel.add(lbl);
String[] choices = { "10 MINS","15 MINS", "20 MINS","25 MINS","30 MINS"};
final JComboBox<String> cb = new JComboBox<String>(choices);
cb.setVisible(true);
panel.add(cb);
JButton btn = new JButton("OK");
panel.add(btn);
frame.setVisible(true);
}
}
Upvotes: 2