Please help

marc172

Member
55 posts 2 reactions
Joined
Feb 22, 2013
Messages
55
Status
Activity Streak
Hello, I am a beginner in java programming... Can anyone help me how to add items in JComboBox inputted from JTextField by using JButton??

Thank You... :)
 

Pesh

Sannin of the Scrolls 📜
Elite
5,501 posts 435 reactions
7
Joined
Oct 21, 2008
Messages
5,501
Status
Activity Streak
Hello, I am a beginner in java programming... Can anyone help me how to add items in JComboBox inputted from JTextField by using JButton??

Thank You... :)

Code:
jb.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
               String txt= jtf.getText();
               jcb.addItem(txt);
            }
        });

Where jb is the JButton, jtf the text field and jcb the combo box.
The text field and the combo box must be either constants or global variables. In that case it's better if you make them global as you won't be able to edit the combo box if it's a constant.
If you want the complete program PM and I'll give it to you.
 

marc172

Member
55 posts 2 reactions
Joined
Feb 22, 2013
Messages
55
Status
Activity Streak
Code:
jb.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
               String txt= jtf.getText();
               jcb.addItem(txt);
            }
        });

Where jb is the JButton, jtf the text field and jcb the combo box.
The text field and the combo box must be either constants or global variables. In that case it's better if you make them global as you won't be able to edit the combo box if it's a constant.
If you want the complete program PM and I'll give it to you.

Thanks bro... :) can you please pm me the complete program? :)
 
Top