Search code examples
stringjtextfieldjcombobox

store string from 3 jcombobox's in one jtextfield


Currently when clicking the jButton, jComboBox1 Text will appear in jTextArea1 but text from jComboBox2 does not appear. Any pointers on how to have the text from both comboboxes appear in 1 textfield?

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jTextArea1.setText(jComboBox1.getSelectedItem().toString()); jTextArea1.setText(jComboBox2.getSelectedItem().toString());


Solution

  • I figured it out. Not sure if this is the most efficient considering there are a total of about 15 comboboxes but here it is.

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        String severity1;
        String s1 = s1ComboBox.getSelectedItem() + " ";
        String timing1;
        String t1 = t1ComboBox.getSelectedItem() + " ";
        jTextField2.setText(s1 + t1);
    

    If anyone knows a more efficient way please let me know.