Hi guys, I need some help regarding JComboBox. I want to link the JComboBox with JTextField and this is the code that i did. It contains error and I need some guidelines for it.Thx

private void typeof_patronJComboBoxitemStateChanged(ItemEvent event)
{
	
	// clear JTextFields
      clearComponents();
      
      // determine whether checkbox selected
      if (event.getStateChange()== ItemEvent.SELECTED)
   		offaddressJTextField.setEditable( true[typeof_patronJComboBox.getSelectedIndex(0)]);
      
	// enable or make editable appropriate components
      addJButton.setEnabled( true );
      PatrondetailsJPanelEditable( true );
      
     // grab focus
      nameJTextField.requestFocusInWindow();
      
}

Recommended Answers

All 3 Replies

Show your typeof_patronJComboBox model. Post more code ... as attachment (for example). Line 9 is on the first look looks is on its way a strange.

This is the coding for the JComboBox :

// array contains options for book_statusJComboBox
   private String[] type = { "Faculty", "Graduate Student", "Undergraduate Student" };

 // set up typeof_patronJLabel
      typeof_patronJLabel = new JLabel();
      typeof_patronJLabel.setBounds( 15, 60, 180, 30 );
      typeof_patronJLabel.setText( "Type of patron:" );
      PatrondetailsJPanel.add( typeof_patronJLabel );

      // set up typeof_patronJComboBox
      typeof_patronJComboBox = new JComboBox(type);
      typeof_patronJComboBox.setBounds( 105, 60, 280, 25 );
      typeof_patronJComboBox.setEditable( false );
      PatrondetailsJPanel.add( typeof_patronJComboBox );
      typeof_patronJComboBox.setMaximumRowCount(3);
      typeof_patronJComboBox.addItemListener(
      new ItemListener()
        {
            // handle JComboBox event
            public void itemStateChanged(ItemEvent event)
            {
                typeof_patronJComboBoxitemStateChanged(event);
            }
        }
        );



private void typeof_patronJComboBoxitemStateChanged(ItemEvent event)
{

    // clear JTextFields
      clearComponents();

      // determine whether checkbox selected
      //if (event.getStateChange()== ItemEvent.SELECTED)
        //offaddressJTextField.setEditable( true[typeof_patronJComboBox.getSelectedIndex(0)]);

    // enable or make editable appropriate components
      addJButton.setEnabled( true );
      PatrondetailsJPanelEditable( true );

     // grab focus
      nameJTextField.requestFocusInWindow();

}  // end method typeof_patronJComboBoxitemStateChanged

The problem is I need to link the JComboBox with JTextField and I dont have idea how to do it.
The JComboBox should work like this :
- When I choose any item from the JComboBox, it should enable the JTextField so that user can enter the data because there are 3 type of patrons in the JComboBox and each of it held different kind of properties.

Hence I need some help on this coding. Thanks

The JComboBox is for the type of patrons and not for the book_status. Some spelling errors. Sorry guys.
Anyway I need your help. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.