ToggleButton oddity  
Author Message
Aki "Sus"Laukkanen





PostPosted: 2004-10-13 17:47:00 Top

java-programmer, ToggleButton oddity I'm trying to create a set of video controls on my application.
I've added JToggleButtons named jtoggleButtonPlay, jToggleButtonPause
and jToggleButtonRew. (All part of the same ButtonGroup
buttonGroupVideoControls)
There's also a combination of JSlider (jSliderFps) and a
JFormattedTextBox (jFormattedTextBoxFps) to set the display rate.

The below code is the change listener for the buttons.
(Each button has a
jToggleButtonX.addChangeListener(new ToggleButtonListener());
line for them)

class ToggleButtonListener implements ChangeListener{
/**
* stateChanged
*
* @param e ChangeEvent
*/
public void stateChanged(ChangeEvent e) {
JToggleButton source = (JToggleButton)e.getSource();
if(!source.isSelected()){
source.setSelected(true);
}
else{}
if(source==jToggleButtonPlay){
int fps = 25;
jSliderFps.setValue(fps);
}
else{
if(source==jToggleButtonPause){
int fps = 0;
jSliderFps.setValue(fps);
}
else{
if(source==jToggleButtonRew){
//at this time lacks any runnable code
}
else{
System.err.println("Event from an invalid source");
System.exit(-1);
}
}
}
}
}
The jSliderFps:s ChangeListener is set to activate the Play button if
frame rate is set above 0 and the Pause button if frame rate is set to 0.

However, when I run the application, only the first click on the control
buttons counts. After that, I can't either activate the other buttons or
set the active button from the slider's ChangeListener.
Every attempt to activate a button after that seems to cause a
java.lang.StackOverflowError.

Any ideas on what's causing this?

--
-Aki "Sus" Laukkanen