-
Bug
-
Resolution: Duplicate
-
P4
-
8u40
-
U:\>java -version
java version "1.8.0_40-ea"
Java(TM) SE Runtime Environment (build 1.8.0_40-ea-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b11, mixed mode)
On Windows pressing the space bar initiates a 'click' action on a button that has the focus. This is not working for a ToggleButton that is assigned to a ToggleGroup (without the ToggleGroup it does work). Here is a small test program to illustrate (you can comment out the ToggleGroup section to see the space bar working on the same buttons):
import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class ToggleButtonTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
StackPane pane = new StackPane();
pane.getChildren().add(createContent());
stage.setScene(new Scene(pane));
stage.show();
}
private Node createContent() {
FlowPane fp = new FlowPane(2, 2);
ToggleButton tb1 = new ToggleButton("button 1");
ToggleButton tb2 = new ToggleButton("button 2");
ToggleButton tb3 = new ToggleButton("button 3");
ToggleButton tb4 = new ToggleButton("button 4");
// Comment out the following lines...
ToggleGroup tg = new ToggleGroup();
tg.getToggles().add(tb1);
tg.getToggles().add(tb2);
tg.getToggles().add(tb3);
tg.getToggles().add(tb4);
// ...to here, and the space-bar works again to select the buttons
fp.getChildren().add(tb1);
fp.getChildren().add(tb2);
fp.getChildren().add(tb3);
fp.getChildren().add(tb4);
return fp;
}
}
import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class ToggleButtonTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
StackPane pane = new StackPane();
pane.getChildren().add(createContent());
stage.setScene(new Scene(pane));
stage.show();
}
private Node createContent() {
FlowPane fp = new FlowPane(2, 2);
ToggleButton tb1 = new ToggleButton("button 1");
ToggleButton tb2 = new ToggleButton("button 2");
ToggleButton tb3 = new ToggleButton("button 3");
ToggleButton tb4 = new ToggleButton("button 4");
// Comment out the following lines...
ToggleGroup tg = new ToggleGroup();
tg.getToggles().add(tb1);
tg.getToggles().add(tb2);
tg.getToggles().add(tb3);
tg.getToggles().add(tb4);
// ...to here, and the space-bar works again to select the buttons
fp.getChildren().add(tb1);
fp.getChildren().add(tb2);
fp.getChildren().add(tb3);
fp.getChildren().add(tb4);
return fp;
}
}