Please help

marc172

Member
Joined
Feb 22, 2013
Messages
55
Kin
0💸
Kumi
0💴
Trait Points
0⚔️
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

Active member
Elite
Joined
Oct 21, 2008
Messages
5,501
Kin
0💸
Kumi
1,280💴
Trait Points
0⚔️
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
Joined
Feb 22, 2013
Messages
55
Kin
0💸
Kumi
0💴
Trait Points
0⚔️
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