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...![]()
jb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String txt= jtf.getText();
jcb.addItem(txt);
}
});
Thanks bro...Where jb is the JButton, jtf the text field and jcb the combo box.Code:jb.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String txt= jtf.getText(); jcb.addItem(txt); } });
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.