Join 149,486 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,332 people online right now. Registration is fast and FREE... Join Now!
I am trying to make a JComboBox for state that is a drop down with all 50 states. How to create an array with all 50 states without having to right all 50 states out(needs to be uneditable?? And a zip JComboBox that is editable.? I have the GUI done but the comboboxes are whats confusing and the array??? any help would be great. Here is what I got so far.
public class personalInfo extends JFrame implements ActionListener { //construct components JComboBox stateCombo = new JComboBox(); JComboBox zipCombo = new JComboBox();
//construct a panel for each row JPanel firstRow = new JPanel(); JPanel secondRow = new JPanel(); JPanel thirdRow = new JPanel(); JPanel fourthRow = new JPanel(); JPanel fifthRow = new JPanel();
//construct a panel for the fields and buttons JPanel fieldPanel = new JPanel(); //JPanel buttonPanel = new JPanel();
//construct labels and text boxes JLabel firstNameLabel = new JLabel("First Name: "); JTextField firstName = new JTextField(10); JLabel lastNameLabel = new JLabel("Last Name: "); JTextField lastName= new JTextField(15); JLabel cityLabel = new JLabel("City: "); JTextField city = new JTextField(10); JLabel stateLabel = new JLabel("State: "); JTextField state = new JTextField(2); JLabel zipLabel = new JLabel("Zip:"); JTextField zip = new JTextField(9);
public static void main(String[] args) { personalInfo f= new personalInfo(); f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); f.setSize(350,200); f.setTitle("Personal Information"); f.setResizable(false); f.setLocation(200,200); f.setVisible(true); }
public personalInfo() { Container c = getContentPane(); c.setLayout((new BorderLayout())); fieldPanel.setLayout(new GridLayout(8,1)); FlowLayout rowSetup = new FlowLayout(FlowLayout.LEFT,5,3); firstRow.setLayout(rowSetup); secondRow.setLayout(rowSetup); thirdRow.setLayout(rowSetup); fourthRow.setLayout(rowSetup);
If you don't want to write out all 50 states, you'll need the information from another source. How about storing them in a file, and loading them from there?
Do you know any any other arraylists that are already done? Or is writing them out the only way?
QUOTE(Amadeus @ 16 May, 2007 - 03:59 PM)
If you don't want to write out all 50 states, you'll need the information from another source. How about storing them in a file, and loading them from there?
public class personalInfo extends JFrame implements ActionListener { //construct components JComboBox stateCombo = new JComboBox(); JComboBox zipCombo = new JComboBox();
//construct a panel for each row JPanel firstRow = new JPanel(); JPanel secondRow = new JPanel(); JPanel thirdRow = new JPanel(); JPanel fourthRow = new JPanel(); JPanel fifthRow = new JPanel();
//construct a panel for the fields and buttons JPanel fieldPanel = new JPanel(); //JPanel buttonPanel = new JPanel();
//construct labels and text boxes JLabel firstNameLabel = new JLabel("First Name: "); JTextField firstName = new JTextField(10); JLabel lastNameLabel = new JLabel("Last Name: "); JTextField lastName= new JTextField(15); JLabel cityLabel = new JLabel("City: "); JTextField city = new JTextField(10); JLabel stateLabel = new JLabel("State: "); JTextField state = new JTextField(2); JLabel zipLabel = new JLabel("Zip:"); JTextField zip = new JTextField(9);
public static void main(String[] args) { personalInfo f= new personalInfo(); f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); f.setSize(350,200); f.setTitle("Personal Information"); f.setResizable(false); f.setLocation(200,200); f.setVisible(true); }
public personalInfo() { Container c = getContentPane(); c.setLayout((new BorderLayout())); fieldPanel.setLayout(new GridLayout(8,1)); FlowLayout rowSetup = new FlowLayout(FlowLayout.LEFT,5,3); firstRow.setLayout(rowSetup); secondRow.setLayout(rowSetup); thirdRow.setLayout(rowSetup); fourthRow.setLayout(rowSetup);
//construct a panel for each row JPanel firstRow = new JPanel(); JPanel secondRow = new JPanel(); JPanel thirdRow = new JPanel(); JPanel fourthRow = new JPanel(); JPanel fifthRow = new JPanel();
//construct components
JComboBox zipCombo = new JComboBox(zipCode); JComboBox stateCombo = new JComboBox(states);
//construct a panel for the fields and buttons JPanel fieldPanel = new JPanel();
//construct labels and text boxes JLabel firstNameLabel = new JLabel("First Name: "); JTextField firstName = new JTextField(10); JLabel lastNameLabel = new JLabel("Last Name: "); JTextField lastName= new JTextField(15); JLabel cityLabel = new JLabel("City: "); JTextField city = new JTextField(10); JLabel stateLabel = new JLabel("State: "); JTextField state = new JTextField(2); JLabel zipLabel = new JLabel("Zip:"); JTextField zip = new JTextField(9);
//create the content pane public Container createContentPane() { //populate the JComboBox stateCombo.addActionListener(this); zipCombo.addActionListener(this); zipCombo.setEditable(true); }
public static void main(String[] args) { personalInfo f= new personalInfo(); f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); f.setSize(350,200); f.setTitle("Personal Information"); f.setResizable(false); f.setLocation(200,200); f.setVisible(true); }
public personalInfo() { Container c = getContentPane(); c.setLayout((new BorderLayout())); fieldPanel.setLayout(new GridLayout(8,1)); FlowLayout rowSetup = new FlowLayout(FlowLayout.LEFT,5,3); firstRow.setLayout(rowSetup); secondRow.setLayout(rowSetup); thirdRow.setLayout(rowSetup); fourthRow.setLayout(rowSetup);