Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Programmatic Events  RSS feed

 
G Baker
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, this is my second real week of Java programming and I have a question about events.

I have a JCheckBox that, when clicked, enables some additional GUI components.

I save settings on the dialog, so when the user goes back in, if the checkbox was unchecked, the additional GUI components should be disabled.

From what I experienced and have gathered on the web, programmatically calling the JCheckBox.setSelected() method does not invoke the ActionListeners.

Is there tried and true pattern that is used in java for when you *want* the action listeners to be called after programatically calling a function that would normally call event handlers?

Thanks!
 
Tony Docherty
Bartender
Posts: 3200
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For components that extend AbstractButton, which JCheckBox does, you can call the doClick() method which simulates the user clicking on the component and thus generates the appropriate events.

Additional Info: Calling doClick() on a JCheckBox will toggle the current state in the same way a user clicking on the component will so you will need to make sure the check box in the wrong state before calling doClick()
[ August 14, 2007: Message edited by: Tony Docherty ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!