Java Code Examples for javafx.scene.control.ToggleGroup#selectToggle()
The following examples show how to use
javafx.scene.control.ToggleGroup#selectToggle() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SessionManager.java From mokka7 with Eclipse Public License 1.0 | 6 votes |
public void bind(final ToggleGroup toggleGroup, final String propertyName) { try { String value = props.getProperty(propertyName); if (value != null) { int selectedToggleIndex = Integer.parseInt(value); toggleGroup.selectToggle(toggleGroup.getToggles().get(selectedToggleIndex)); } } catch (Exception ignored) { } toggleGroup.selectedToggleProperty().addListener(new InvalidationListener() { @Override public void invalidated(Observable o) { if (toggleGroup.getSelectedToggle() == null) { props.remove(propertyName); } else { props.setProperty(propertyName, Integer.toString(toggleGroup.getToggles().indexOf(toggleGroup.getSelectedToggle()))); } } }); }
Example 2
Source File: SidebarToggleGroupBehavior.java From phoenicis with GNU Lesser General Public License v3.0 | 6 votes |
/** * 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(); } } } }
Example 3
Source File: SessionContext.java From jfxvnc with Apache License 2.0 | 6 votes |
public void bind(final ToggleGroup toggleGroup, final String propertyName) { try { String value = props.getProperty(propertyName); if (value != null) { int selectedToggleIndex = Integer.parseInt(value); toggleGroup.selectToggle(toggleGroup.getToggles().get(selectedToggleIndex)); } } catch (Exception ignored) { } toggleGroup.selectedToggleProperty().addListener(o -> { if (toggleGroup.getSelectedToggle() == null) { props.remove(propertyName); } else { props.setProperty(propertyName, Integer.toString(toggleGroup.getToggles().indexOf(toggleGroup.getSelectedToggle()))); } }); }
Example 4
Source File: PreferenceOutputPane.java From pdfsam with GNU Affero General Public License v3.0 | 6 votes |
@Inject public PreferenceOutputPane(@Named("smartRadio") PreferenceRadioButton smartRadio, @Named("compressionEnabled") PreferenceCheckBox compressionEnabled) { I18nContext i18n = DefaultI18nContext.getInstance(); ToggleGroup group = new ToggleGroup(); RadioButton manualRadio = new RadioButton(i18n.i18n("Manually selected")); manualRadio.setToggleGroup(group); manualRadio.getStyleClass().addAll(Style.VITEM.css()); manualRadio.setId("manualRadio"); smartRadio.getStyleClass().addAll(Style.VITEM.css()); smartRadio.setToggleGroup(group); smartRadio.setGraphic(helpIcon(DefaultI18nContext.getInstance() .i18n("Automatically set the destination directory to the selected PDF document directory"))); smartRadio.getStyleClass().addAll(Style.WITH_HELP.css()); if (isNull(group.getSelectedToggle())) { group.selectToggle(manualRadio); } getChildren().addAll(manualRadio, smartRadio, compressionEnabled); getStyleClass().addAll(Style.CONTAINER.css()); }
Example 5
Source File: ToggleButtonSample.java From marathonv5 with Apache License 2.0 | 5 votes |
public ToggleButtonSample() { // create label to show result of selected toggle button final Label label = new Label(); label.setStyle("-fx-font-size: 2em;"); // create 3 toggle buttons and a toogle group for them final ToggleButton tb1 = new ToggleButton("Cat"); final ToggleButton tb2 = new ToggleButton("Dog"); final ToggleButton tb3 = new ToggleButton("Horse"); ToggleGroup group = new ToggleGroup(); tb1.setToggleGroup(group); tb2.setToggleGroup(group); tb3.setToggleGroup(group); group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() { @Override public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle selectedToggle) { if(selectedToggle!=null) { label.setText(((ToggleButton) selectedToggle).getText()); } else { label.setText("..."); } } }); // select the first button to start with group.selectToggle(tb1); // add buttons and label to grid and set their positions GridPane.setConstraints(tb1,0,0); GridPane.setConstraints(tb2,1,0); GridPane.setConstraints(tb3,2,0); GridPane.setConstraints(label,0,1,3,1); GridPane grid = new GridPane(); grid.setVgap(20); grid.setHgap(10); getChildren().add(grid); grid.getChildren().addAll(tb1, tb2, tb3, label); }
Example 6
Source File: ToggleButtonSample.java From marathonv5 with Apache License 2.0 | 5 votes |
public ToggleButtonSample() { // create label to show result of selected toggle button final Label label = new Label(); label.setStyle("-fx-font-size: 2em;"); // create 3 toggle buttons and a toogle group for them final ToggleButton tb1 = new ToggleButton("Cat"); final ToggleButton tb2 = new ToggleButton("Dog"); final ToggleButton tb3 = new ToggleButton("Horse"); ToggleGroup group = new ToggleGroup(); tb1.setToggleGroup(group); tb2.setToggleGroup(group); tb3.setToggleGroup(group); group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() { @Override public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle selectedToggle) { if(selectedToggle!=null) { label.setText(((ToggleButton) selectedToggle).getText()); } else { label.setText("..."); } } }); // select the first button to start with group.selectToggle(tb1); // add buttons and label to grid and set their positions GridPane.setConstraints(tb1,0,0); GridPane.setConstraints(tb2,1,0); GridPane.setConstraints(tb3,2,0); GridPane.setConstraints(label,0,1,3,1); GridPane grid = new GridPane(); grid.setVgap(20); grid.setHgap(10); getChildren().add(grid); grid.getChildren().addAll(tb1, tb2, tb3, label); }
Example 7
Source File: CalculatorFXMLController.java From dctb-utfpr-2018-1 with Apache License 2.0 | 5 votes |
@Override public void initialize(URL url, ResourceBundle rb) { Message.setText(""); tg = new ToggleGroup(); ParserRadio.setToggleGroup(tg); BasicRadio.setToggleGroup(tg); tg.selectToggle(ParserRadio); }
Example 8
Source File: ApkToolView.java From ApkToolPlus with Apache License 2.0 | 5 votes |
@Override public void initialize(URL location, ResourceBundle resources) { // 初始化toggle button ToggleGroup toggleGroup = new ToggleGroup(); toggleGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) -> { if (newValue != null) { Integer flag = (Integer) newValue.getUserData(); togglePage(flag); } else { toggleGroup.selectToggle(oldValue); } }); toggleDecompile.setToggleGroup(toggleGroup); toggleDecompile.setUserData(1); toggleRecompile.setToggleGroup(toggleGroup); toggleRecompile.setUserData(2); toggleApkSign.setToggleGroup(toggleGroup); toggleApkSign.setUserData(3); // 默认选择反编译界面 toggleGroup.selectToggle(toggleDecompile); // 默认不显示打开输出目录按钮 btnOpenDecompileOut.setVisible(false); btnOpenRecompileOut.setVisible(false); btnOpenApkSignOut.setVisible(false); }
Example 9
Source File: BreakingNewsDemoView.java From htm.java-examples with GNU Affero General Public License v3.0 | 4 votes |
/** * Demonstrates the construction and usage of the {@link SegmentedButtonBar} * @return */ public HBox createSegmentedButtonBar() { ToggleButton button1 = new ToggleButton("Start"); button1.getStyleClass().addAll("first"); button1.setOnAction(e -> { Platform.runLater(() -> { if(mode == Mode.MANUAL) { runOneBtn.setDisable(false); } startActionProperty.set(true); }); }); ToggleButton button2 = new ToggleButton("Stop"); button2.getStyleClass().addAll("last"); button2.setOnAction(e -> { Platform.runLater(() -> { startActionProperty.set(false); }); }); ToggleButton button3 = new ToggleButton("Auto"); button3.getStyleClass().addAll("first"); button3.setOnAction(e -> { Platform.runLater(() -> { mode = Mode.AUTO; autoModeProperty.set(mode); }); }); ToggleButton button4 = new ToggleButton("Manual"); button4.getStyleClass().addAll("last"); button4.setOnAction(e -> { Platform.runLater(() -> { mode = Mode.MANUAL; autoModeProperty.set(mode); }); }); Button button5 = runOneBtn = new Button("Run One"); button5.getStyleClass().addAll("only"); button5.setDisable(true); button5.setOnAction(e -> { Platform.runLater(() -> { runOneProperty.set(runOneProperty.get() + 1); }); }); runDisableProperty.addListener((v, o, n) -> { button5.setDisable(n); }); ToggleGroup group = new ToggleGroup(); group.getToggles().addAll(button1, button2); group.selectToggle(button2); ToggleGroup group2 = new ToggleGroup(); group2.getToggles().addAll(button3, button4); group2.selectToggle(button3); group2.selectedToggleProperty().addListener((v, o, n) -> { if(n == null) return; if(n.equals(button4)) { Platform.runLater(() -> { mode = Mode.MANUAL; group.selectToggle(button2); startActionProperty.set(false); }); }else{ Platform.runLater(() -> { mode = Mode.AUTO; startActionProperty.set(false); group.selectToggle(button2); button5.setDisable(true); }); } }); HBox displayBox = new HBox(); displayBox.setSpacing(20); displayBox.setAlignment(Pos.CENTER); SegmentedButtonBar buttonBar = new SegmentedButtonBar(); buttonBar.getChildren().addAll(button1, button2); SegmentedButtonBar buttonBar2 = new SegmentedButtonBar(); buttonBar2.getChildren().addAll(button3, button4); SegmentedButtonBar buttonBar3 = new SegmentedButtonBar(); buttonBar3.getChildren().addAll(button5); displayBox.getChildren().addAll(buttonBar, buttonBar2, buttonBar3); return displayBox; }
Example 10
Source File: FeeOptionWindow.java From bisq with GNU Affero General Public License v3.0 | 4 votes |
private void addContent() { Label label = addLabel(gridPane, ++rowIndex, Res.get("feeOptionWindow.info")); GridPane.setColumnSpan(label, 2); GridPane.setHalignment(label, HPos.LEFT); toggleGroup = new ToggleGroup(); Tuple3<Label, RadioButton, RadioButton> tuple = addTopLabelRadioButtonRadioButton(gridPane, ++rowIndex, toggleGroup, Res.get("feeOptionWindow.optionsLabel"), "BTC", "BSQ", 0); RadioButton radioButtonBTC = tuple.second; RadioButton radioButtonBSQ = tuple.third; makerFeeTextField = FormBuilder.addTopLabelTextField(gridPane, ++rowIndex, Res.get("createOffer.currencyForFee"), makerFeeWithCodeProperty.get()).second; toggleChangeListener = (observable, oldValue, newValue) -> { final boolean isBtc = newValue == radioButtonBTC; selectionChangedHandler.accept(isBtc); if (!isBsqForFeeAvailable && !isBtc) { if (missingBsq != null) { // We don't call hide() because we want to keep the blurred bg if (stage != null) stage.hide(); else log.warn("Stage is null"); cleanup(); onHidden(); new Popup().warning(missingBsq) .actionButtonTextWithGoTo("navigation.dao.wallet.receive") .onAction(() -> { UserThread.runAfter(() -> { hide(); navigation.navigateTo(MainView.class, DaoView.class, BsqWalletView.class, BsqReceiveView.class); }, 100, TimeUnit.MILLISECONDS); }) .closeButtonText(Res.get("feeOptionWindow.useBTC")) .onClose(() -> { selectionChangedHandler.accept(true); closeHandler.run(); }) .show(); } UserThread.execute(() -> { toggleGroup.selectToggle(radioButtonBTC); radioButtonBSQ.setDisable(true); }); } }; toggleGroup.selectedToggleProperty().addListener(toggleChangeListener); toggleGroup.selectToggle(!isBsqForFeeAvailable || isCurrencyForMakerFeeBtc ? radioButtonBTC : radioButtonBSQ); makerFeeTextField.textProperty().bind(makerFeeWithCodeProperty); }
Example 11
Source File: MetadataOverview.java From sis with Apache License 2.0 | 4 votes |
public MetadataOverview(final DefaultMetadata md, final String fromFile) { this.metadata = md; this.fromFile = fromFile; VBox root = new VBox(); root.setStyle("-fx-background-color: linear-gradient(to bottom right, #aeb7c4, #fafafa);"); // Creation of the differents views. VBox summaryView = createSummaryView(); MetadataNode advancedView = new MetadataNode(md.asTreeTable()); advancedView.setMaxHeight(Double.MAX_VALUE); VBox.setVgrow(advancedView, Priority.ALWAYS); // Create and configure view selection buttons. ToggleGroup buttonGroup = new ToggleGroup(); ToggleButton tb1 = new ToggleButton("Summary"); ToggleButton tb2 = new ToggleButton("Advanced"); tb1.setStyle("-fx-text-fill: white; -fx-font-family: Arial Narrow;-fx-font-weight: bold; -fx-background-color: linear-gradient(#61a2b1, #2A5058); -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 5, 0.0 , 0 , 1 ); -fx-padding: 0.8em;"); tb2.setStyle("-fx-text-fill: white; -fx-font-family: Arial Narrow;-fx-font-weight: bold; -fx-background-color: linear-gradient(#61a2b1, #2A5058); -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 5, 0.0 , 0 , 1 ); -fx-padding: 0.8em;"); tb1.setToggleGroup(buttonGroup); tb1.setSelected(true); tb1.setDisable(true); tb2.setToggleGroup(buttonGroup); buttonGroup.selectToggle(tb1); buttonGroup.selectedToggleProperty().addListener((ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) -> { if (tb2.isSelected()) { tb2.setDisable(true); root.getChildren().remove(summaryView); root.getChildren().add(advancedView); tb1.setDisable(false); } else { tb1.setDisable(true); root.getChildren().add(summaryView); root.getChildren().remove(advancedView); tb2.setDisable(false); } }); HBox toggleGroupLayout = new HBox(); toggleGroupLayout.getChildren().addAll(tb1, tb2); toggleGroupLayout.setPadding(new Insets(0, 0, 10, 0)); root.getChildren().add(toggleGroupLayout); root.getChildren().add(summaryView); this.getChildren().add(root); }