Java Code Examples for javafx.scene.control.ToggleButton#setToggleGroup()

The following examples show how to use javafx.scene.control.ToggleButton#setToggleGroup() . 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: CircuitSim.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 9 votes vote down vote up
private ToggleButton setupButton(ToggleGroup group, ComponentLauncherInfo componentInfo) {
	ToggleButton button = new ToggleButton(componentInfo.name.getValue(), setupImageView(componentInfo.image));
	button.setAlignment(Pos.CENTER_LEFT);
	button.setToggleGroup(group);
	button.setMinHeight(30);
	button.setMaxWidth(Double.MAX_VALUE);
	button.setOnAction(e -> {
		if(button.isSelected()) {
			modifiedSelection(componentInfo);
		} else {
			modifiedSelection(null);
		}
	});
	GridPane.setHgrow(button, Priority.ALWAYS);
	return button;
}
 
Example 2
Source File: SettingsActivity.java    From ApkToolPlus with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化选择项
 */
private void initItems(){
    // 左边的选择项
    ObservableList<Node> items = boxItems.getChildren();
    ToggleGroup group = new ToggleGroup();
    // 关联group和index
    for(int index=0; index<items.size(); ++index){
        ToggleButton item = (ToggleButton) items.get(index);
        item.setToggleGroup(group);
        item.setUserData(index);
    }
    // 切换监听
    group.selectedToggleProperty().addListener((observable, oldValue, newValue) ->{
        if(newValue != null){
            Integer itemIndex = (Integer) newValue.getUserData();
            showSettingContent(itemIndex);
        }else{
            group.selectToggle(oldValue);
        }
    });
    // 默认选择第一个
    group.getToggles().get(0).setSelected(true);
}
 
Example 3
Source File: ToggleButtonSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
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 4
Source File: ToggleButtonSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
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 5
Source File: ChoiceButtonRepresentation.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private ButtonBase createButton(final String text)
{
    final ToggleButton b = new ToggleButton(text);
    b.getStyleClass().add("action_button");
    b.setToggleGroup(toggle);
    b.setMnemonicParsing(false);
    return b;
}
 
Example 6
Source File: TradesChartsView.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
private ToggleButton getToggleButton(String label, TradesChartsViewModel.TickUnit tickUnit, ToggleGroup toggleGroup, String style) {
    ToggleButton toggleButton = new AutoTooltipToggleButton(label);
    toggleButton.setUserData(tickUnit);
    toggleButton.setToggleGroup(toggleGroup);
    toggleButton.setId(style);
    return toggleButton;
}
 
Example 7
Source File: RichTextDemo.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ToggleButton createToggleButton(ToggleGroup grp, String styleClass, Runnable action, String toolTip) {
    ToggleButton button = new ToggleButton();
    button.setToggleGroup(grp);
    button.getStyleClass().add(styleClass);
    button.setOnAction(evt -> {
        action.run();
        area.requestFocus();
    });
    button.setPrefWidth(25);
    button.setPrefHeight(25);
    if (toolTip != null) {
        button.setTooltip(new Tooltip(toolTip));
    }
    return button;
}
 
Example 8
Source File: Colors.java    From DashboardFx with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void initialize(URL location, ResourceBundle resources) {
    int  col  = 0;
    int  row  = 1;

    for (MaterialDesign color : MaterialDesign.values()) {
        String name     = color.name().replace("_", " ");
        String strWeb   = ColorHelper.web(color.get());
        String strRgb   = ColorHelper.rgb(color.get());
        String text     = String.join("", name, "\n", strWeb, "\n", strRgb);

        MATCHER.reset(color.name());
        String brightness = "";
        while (MATCHER.find()) {
            brightness = MATCHER.group(1).replace("_", " ");
        }

        ToggleButton toggle = new ToggleButton(
                color.name().contains("0") ? "" : color.name() + "\n" + brightness);
        toggle.setToggleGroup(group);
        toggle.setAlignment(Pos.CENTER);
        toggle.setTextFill(Color.WHITE);
        toggle.setCursor(Cursor.HAND);
        toggle.setAlignment(Pos.CENTER);
        toggle.setPrefSize(BOX_WIDTH, BOX_HEIGHT);

        boolean isBox = false;

        if(!color.name().contains("0")){
            toggle.setMouseTransparent(true);
            toggle.setStyle("-fx-background-color : white; -fx-text-fill : -gray;" +
                    "-fx-border-color : transparent transparent -light-gray transparent;" +
                    "-fx-background-radius : 0");
            toggle.setMinWidth(100D);
        } else {
            toggle.setStyle("-fx-background-color : " +  formatHexString(color.get()) + ";" +
                    "-fx-background-radius : 0");
            isBox = true;
        }

        toggle.setOnMousePressed(event -> {
            String clipboardContent = "Color.web(\"" +
                    strWeb +
                    "\");\n" +
                    "Color." +
                    strRgb +
                    ";";

            Clipboard clipboard  = Clipboard.getSystemClipboard();
            ClipboardContent content    = new ClipboardContent();
            content.putString(clipboardContent);
            clipboard.setContent(content);
        });

        boolean finalIsBox = isBox;
        toggle.setOnMouseEntered(event -> {
            if(finalIsBox){
            toggle.setBackground(new Background(new BackgroundFill(color.get(), new CornerRadii(10), Insets.EMPTY)));
            toggle.setStyle("-fx-background-radius : 10px; -fx-background-color : " + formatHexString(color.get())
                    + ";");
            }
        });

        toggle.setOnMouseExited(event -> {
            if(finalIsBox){
                toggle.setStyle("-fx-background-radius : 0px; -fx-background-color : " + formatHexString(color.get()) + ";");
            }
        });



        Tooltip tooltip = new Tooltip(text);
        Tooltip.install(toggle, tooltip);
        grid.add(toggle, col, row);
        col++;

        if (row > 16) {
            if (col == 11) {
                col = 0;
                row++;
            }
        } else {
            if (col == 15) {
                col = 0;
                row++;
            }
        }
    }
    grid.setHgap(1);
    grid.setVgap(1);
    grid.getRowConstraints().clear();
    grid.getColumnConstraints().clear();

}
 
Example 9
Source File: ToggleButtonSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage stage) {
    stage.setTitle("Toggle Button Sample");
    stage.setWidth(250);
    stage.setHeight(180);

    HBox hbox = new HBox();
    VBox vbox = new VBox();

    Scene scene = new Scene(new Group(vbox));
    stage.setScene(scene);
    scene.getStylesheets().add("togglebuttonsample/ControlStyle.css");

    Rectangle rect = new Rectangle();
    rect.setHeight(50);
    rect.setFill(Color.WHITE);
    rect.setStroke(Color.DARKGRAY);
    rect.setStrokeWidth(2);
    rect.setArcHeight(10);
    rect.setArcWidth(10);

    final ToggleGroup group = new ToggleGroup();

    group.selectedToggleProperty().addListener((ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle) -> {
        if (new_toggle == null)
            rect.setFill(Color.WHITE);
        else
            rect.setFill((Color) group.getSelectedToggle().getUserData());
    });

    ToggleButton tb1 = new ToggleButton("Minor");
    tb1.setToggleGroup(group);
    tb1.setUserData(Color.LIGHTGREEN);
    tb1.setSelected(true);
    tb1.getStyleClass().add("toggle-button1");

    ToggleButton tb2 = new ToggleButton("Major");
    tb2.setToggleGroup(group);
    tb2.setUserData(Color.LIGHTBLUE);
    tb2.getStyleClass().add("toggle-button2");

    ToggleButton tb3 = new ToggleButton("Critical");
    tb3.setToggleGroup(group);
    tb3.setUserData(Color.SALMON);
    tb3.getStyleClass().add("toggle-button3");

    hbox.getChildren().addAll(tb1, tb2, tb3);

    vbox.getChildren().add(new Label("Priority:"));
    vbox.getChildren().add(hbox);
    vbox.getChildren().add(rect);
    vbox.setPadding(new Insets(20, 10, 10, 20));

    stage.show();
    rect.setWidth(hbox.getWidth());
}
 
Example 10
Source File: LanguagePanel.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Create a new LanguagePanel
 */
public LanguagePanel()
{
	originalLanguage = ConfigurationSettings.getLanguage();

	if ((SettingsHandler.getGameAsProperty().get() != null) && (SettingsHandler.getGameAsProperty().get().getUnitSet() != null))
	{
		originalUnitSet = SettingsHandler.getGameAsProperty().get().getUnitSet().getDisplayName();
	}
	else
	{
		originalUnitSet = "";
	}

	VBox vbox = new VBox();

	for (LanguageChoice languageChoice: LanguageChoice.values())
	{
		ToggleButton languageButton = new RadioButton();
		languageButton.setUserData(languageChoice.getShortName());
		languageButton.setText(languageChoice.getLongName());
		languageButton.setToggleGroup(languageChoiceGroup);
		vbox.getChildren().add(languageButton);
	}

	Collection<UnitSet> unitSets = SettingsHandler.getGameAsProperty().get().getModeContext().getReferenceContext()
	                                              .getConstructedCDOMObjects(UnitSet.class);
	Collection<String> names = unitSets.stream()
	                                   .filter(Objects::nonNull)
	                                   .map(UnitSet::getDisplayName)
	                                   .collect(Collectors.toUnmodifiableList());
	ObservableList<String> unitSetNames = FXCollections.observableArrayList(names);
	unitSetType = new ChoiceBox<>();
	unitSetType.setItems(unitSetNames);
	Label unitSetLabel = new Label(LanguageBundle.getString("in_Prefs_unitSetType"));
	unitSetLabel.setLabelFor(unitSetType);
	vbox.getChildren().add(unitSetLabel);
	vbox.getChildren().add(unitSetType);

	Node restartInfo = new Text(LanguageBundle.getString("in_Prefs_restartInfo"));
	vbox.getChildren().add(restartInfo);

	this.add(GuiUtility.wrapParentAsJFXPanel(vbox));
}
 
Example 11
Source File: LanguagePanel.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Create a new LanguagePanel
 */
public LanguagePanel()
{
	originalLanguage = ConfigurationSettings.getLanguage();

	if ((SettingsHandler.getGameAsProperty().get() != null) && (SettingsHandler.getGameAsProperty().get().getUnitSet() != null))
	{
		originalUnitSet = SettingsHandler.getGameAsProperty().get().getUnitSet().getDisplayName();
	}
	else
	{
		originalUnitSet = "";
	}

	VBox vbox = new VBox();

	for (LanguageChoice languageChoice: LanguageChoice.values())
	{
		ToggleButton languageButton = new RadioButton();
		languageButton.setUserData(languageChoice.getShortName());
		languageButton.setText(languageChoice.getLongName());
		languageButton.setToggleGroup(languageChoiceGroup);
		vbox.getChildren().add(languageButton);
	}

	Collection<UnitSet> unitSets = SettingsHandler.getGameAsProperty().get().getModeContext().getReferenceContext()
	                                              .getConstructedCDOMObjects(UnitSet.class);
	Collection<String> names = unitSets.stream()
	                                   .filter(Objects::nonNull)
	                                   .map(UnitSet::getDisplayName)
	                                   .collect(Collectors.toUnmodifiableList());
	ObservableList<String> unitSetNames = FXCollections.observableArrayList(names);
	unitSetType = new ChoiceBox<>();
	unitSetType.setItems(unitSetNames);
	Label unitSetLabel = new Label(LanguageBundle.getString("in_Prefs_unitSetType"));
	unitSetLabel.setLabelFor(unitSetType);
	vbox.getChildren().add(unitSetLabel);
	vbox.getChildren().add(unitSetType);

	Node restartInfo = new Text(LanguageBundle.getString("in_Prefs_restartInfo"));
	vbox.getChildren().add(restartInfo);

	this.add(GuiUtility.wrapParentAsJFXPanel(vbox));
}
 
Example 12
Source File: MetadataOverview.java    From sis with Apache License 2.0 4 votes vote down vote up
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);
}