Combo Box
The default JComboBox is the uneditable combom box. The second form, called the editable, have a text field.
import java.awt.Dimension;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class App extends JFrame {
public static void main(String[] args) {
JFrame frame = new App();
frame.setBounds(200, 200, 300, 200);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setVisible(true);
}
public App() {
JComboBox comboBox =
new JComboBox( new Object[] {"Movie 1", "Movie 2"} );
comboBox.setPreferredSize(new Dimension(200, 27)); // Look Here
// Without this line, width is minim
JPanel panel = new JPanel();
panel.add(comboBox);
add(panel);
}
}
Last update: 432 days ago