Reputation: 1138
I have a JComboBox. I want to retrieve the data from it. I know I use the getSelectedItem() method. But then once I get it, I want it to convert it to a String somehow..or ultimately, display it on a JTextField.
String[] fluids = { " ", "string 1", "String 2"};
fluidsList = new JComboBox(fluids);
Upvotes: 0
Views: 5774
Reputation: 108957
Assuming jTextField1 is your JTextField and fluidsList is your JComboBox, you'll have to have something like this
jTextField1.setText(fluidsList.getSelectedItem() == null ? "" : fluidsList.getSelectedItem().toString() );
Upvotes: 1