use of javafx.scene.control.ToggleGroup in project POL-POM-5 by PhoenicisOrg.
the class SidebarToggleGroupBehavior method selectFirstToggleButton.
/**
* Ensures, that always a button is selected:
* - if because of an invalidation of the input list the selection is lost, the selection is reapplied
* - if no button is selected, select the first button
*/
private void selectFirstToggleButton() {
final ToggleGroup toggleGroup = getSkin().getToggleGroup();
if (toggleGroup.getSelectedToggle() == null && !toggleGroup.getToggles().isEmpty()) {
final E selectedElement = getControl().selectedElementProperty().getValue();
if (selectedElement != null && getControl().getElements().contains(selectedElement)) {
// 1 if an "all" button exists, 0 otherwise
final int offset = toggleGroup.getToggles().size() - getControl().getElements().size();
final int index = getControl().getElements().indexOf(getControl().selectedElementProperty().getValue());
// reselect the previously selected item
toggleGroup.selectToggle(toggleGroup.getToggles().get(offset + index));
} else {
final Toggle firstToggle = toggleGroup.getToggles().get(0);
// trigger the first item in the toggle group
if (firstToggle instanceof ToggleButton) {
((ToggleButton) firstToggle).fire();
}
}
}
}
use of javafx.scene.control.ToggleGroup in project Board-Instrumentation-Framework by intel.
the class Demo method initBack.
private Pane initBack(final FlipPanel flipPanel, final StackPane FRONT_PANEL) {
Region backButton = new Region();
backButton.getStyleClass().add("back-button");
backButton.addEventHandler(MouseEvent.MOUSE_CLICKED, EVENT -> flipPanel.flipToFront());
ToggleGroup group = new ToggleGroup();
final RadioButton standardGreen = new RadioButton("Green");
standardGreen.setToggleGroup(group);
standardGreen.setSelected(true);
standardGreen.setOnAction(event -> FRONT_PANEL.setBackground(new Background(new BackgroundFill(Color.GREEN, CornerRadii.EMPTY, Insets.EMPTY))));
final RadioButton amber = new RadioButton("Red");
amber.setToggleGroup(group);
amber.setOnAction(event -> FRONT_PANEL.setBackground(new Background(new BackgroundFill(Color.RED, CornerRadii.EMPTY, Insets.EMPTY))));
final RadioButton blueDarkBlue = new RadioButton("Blue");
blueDarkBlue.setToggleGroup(group);
blueDarkBlue.setOnAction(event -> FRONT_PANEL.setBackground(new Background(new BackgroundFill(Color.BLUE, CornerRadii.EMPTY, Insets.EMPTY))));
VBox componentsBack = new VBox(backButton, standardGreen, amber, blueDarkBlue);
componentsBack.setSpacing(10);
StackPane back = new StackPane();
back.setPadding(new Insets(20, 20, 20, 20));
back.getStyleClass().add("panel");
back.getChildren().addAll(componentsBack);
return back;
}
Aggregations