• Post Reply Bookmark Topic Watch Topic
  • New Topic

JComboBox ActionListenet problem

 
Chinmay Bajikar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have a JComboBox added as an editor for one of the colunms of JTable.And then I have done a addActionListener() for that combo box.Now when i run my application , and click on the table column ,the ActionEvent is fired 3 times.(I want a new row to be added for the vallid selection in the combo box.)
I have worked with combo boxes bfor and i dont understand this behaviour.
Please explain.
 
Sajee Joseph
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I hope u remember that the JCombobox is not a single control. It is made of several controls. It is a JTextField+List+button.
So i think that the actionlistener is getting fired for all these controls. This is juz a guess. Anyhow can u check the source of these action events?
Regards
Saj
 
Chinmay Bajikar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sajee Joseph:
Hi,
I hope u remember that the JCombobox is not a single control. It is made of several controls. It is a JTextField+List+button.
So i think that the actionlistener is getting fired for all these controls. This is juz a guess. Anyhow can u check the source of these action events?
Regards
Saj

Hi Saj,
You are correct in saying that the Combo Box is composed of JTextField , List and a Button.
But then i did not see this benaviour when the Combo box is used alone or seperately.
I m seeing this only when i add it as an editor in JTable and listen for the ActionEvent to occur on it.
I think this is a problem with how JTable handles it's components.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JTable with a JCombobox and just use the setValueAt() of the DefaultTableModel to handle just what you are talking about. No listeners at all. The setValueAt() will get fired when you make a selection (even if it is the same as the current value).
 
Chinmay Bajikar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Stevens:
I have a JTable with a JCombobox and just use the setValueAt() of the DefaultTableModel to handle just what you are talking about. No listeners at all. The setValueAt() will get fired when you make a selection (even if it is the same as the current value).

Hi Paul,
Do u mean to say that u have created ur own TableModel.Or have u extended the DefaultTableModel.I am using the DefaultTableModel only.If this case how do I do the changes needed for setValueAt().
But I suppose I got an answer as to why the actionPerformed is called twice in these cases.That is bcoz both the user and setValueAt() access the combo box causing the two ActionEvents to be fired.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eextended the DefaultTableModel. Guess I should have been more clear on that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!