Example usage for javafx.scene.control ToggleButton ToggleButton

List of usage examples for javafx.scene.control ToggleButton ToggleButton

Introduction

In this page you can find the example usage for javafx.scene.control ToggleButton ToggleButton.

Prototype

public ToggleButton(String text, Node graphic) 

Source Link

Document

Creates a toggle button with the specified text and icon for its label.

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Toggle Button Sample");
    stage.setWidth(250);/*from   w w  w.jav a  2 s . c  o  m*/
    stage.setHeight(180);

    final ToggleGroup group = new ToggleGroup();

    group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        public void changed(ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle) {
            System.out.println((Color) group.getSelectedToggle().getUserData());
        }
    });
    Node rootIcon = new ImageView(new Image(getClass().getResourceAsStream("root.png")));
    ToggleButton tb1 = new ToggleButton("A", rootIcon);

    tb1.setToggleGroup(group);
    tb1.setUserData(Color.LIGHTGREEN);
    tb1.setSelected(true);

    ToggleButton tb2 = new ToggleButton("B");
    tb2.setToggleGroup(group);
    tb2.setUserData(Color.LIGHTBLUE);
    ToggleButton tb3 = new ToggleButton("C");
    tb3.setToggleGroup(group);
    tb3.setUserData(Color.SALMON);

    HBox hbox = new HBox();

    hbox.getChildren().add(tb1);
    hbox.getChildren().add(tb2);
    hbox.getChildren().add(tb3);

    ((Group) scene.getRoot()).getChildren().add(hbox);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Toggle Button Sample");
    stage.setWidth(250);//w w w . ja v a2s .  c  o  m
    stage.setHeight(180);

    final ToggleGroup group = new ToggleGroup();

    group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        public void changed(ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle) {
            System.out.println((Color) group.getSelectedToggle().getUserData());
        }
    });
    Node rootIcon = new ImageView(new Image(getClass().getResourceAsStream("root.png")));
    ToggleButton tb1 = new ToggleButton("A", rootIcon);
    System.out.println(tb1.isSelected());

    tb1.setToggleGroup(group);
    tb1.setUserData(Color.LIGHTGREEN);
    tb1.setSelected(true);

    ToggleButton tb2 = new ToggleButton("B");
    tb2.setToggleGroup(group);
    tb2.setUserData(Color.LIGHTBLUE);
    ToggleButton tb3 = new ToggleButton("C");
    tb3.setToggleGroup(group);
    tb3.setUserData(Color.SALMON);

    HBox hbox = new HBox();

    hbox.getChildren().add(tb1);
    hbox.getChildren().add(tb2);
    hbox.getChildren().add(tb3);

    ((Group) scene.getRoot()).getChildren().add(hbox);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Toggle Button Sample");
    stage.setWidth(250);//from   www.jav  a 2  s.c  om
    stage.setHeight(180);

    final ToggleGroup group = new ToggleGroup();

    group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        public void changed(ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle) {
            System.out.println((Color) group.getSelectedToggle().getUserData());
        }
    });
    Node rootIcon = new ImageView(new Image(getClass().getResourceAsStream("root.png")));
    ToggleButton tb1 = new ToggleButton("A", rootIcon);
    tb1.setSelected(true);

    tb1.setToggleGroup(group);
    tb1.setUserData(Color.LIGHTGREEN);
    tb1.setSelected(true);

    ToggleButton tb2 = new ToggleButton("B");
    tb2.setToggleGroup(group);
    tb2.setUserData(Color.LIGHTBLUE);
    ToggleButton tb3 = new ToggleButton("C");
    tb3.setToggleGroup(group);
    tb3.setUserData(Color.SALMON);

    HBox hbox = new HBox();

    hbox.getChildren().add(tb1);
    hbox.getChildren().add(tb2);
    hbox.getChildren().add(tb3);

    ((Group) scene.getRoot()).getChildren().add(hbox);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Toggle Button Sample");
    stage.setWidth(250);//  w w  w .j  a  v a  2 s .c  om
    stage.setHeight(180);

    final ToggleGroup group = new ToggleGroup();

    group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        public void changed(ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle) {
            System.out.println((Color) group.getSelectedToggle().getUserData());
        }
    });
    Node rootIcon = new ImageView(new Image(getClass().getResourceAsStream("root.png")));
    ToggleButton tb1 = new ToggleButton("A", rootIcon);
    System.out.println(tb1.toggleGroupProperty());

    tb1.setToggleGroup(group);
    tb1.setUserData(Color.LIGHTGREEN);
    tb1.setSelected(true);

    ToggleButton tb2 = new ToggleButton("B");
    tb2.setToggleGroup(group);
    tb2.setUserData(Color.LIGHTBLUE);
    ToggleButton tb3 = new ToggleButton("C");
    tb3.setToggleGroup(group);
    tb3.setUserData(Color.SALMON);

    HBox hbox = new HBox();

    hbox.getChildren().add(tb1);
    hbox.getChildren().add(tb2);
    hbox.getChildren().add(tb3);

    ((Group) scene.getRoot()).getChildren().add(hbox);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Toggle Button Sample");
    stage.setWidth(250);/*from w ww .  ja va  2s  .c  o m*/
    stage.setHeight(180);

    final ToggleGroup group = new ToggleGroup();

    group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        public void changed(ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle) {
            System.out.println((Color) group.getSelectedToggle().getUserData());
        }
    });
    Node rootIcon = new ImageView(new Image(getClass().getResourceAsStream("root.png")));
    ToggleButton tb1 = new ToggleButton("A", rootIcon);
    System.out.println(tb1.selectedProperty());

    tb1.setToggleGroup(group);
    tb1.setUserData(Color.LIGHTGREEN);
    tb1.setSelected(true);

    ToggleButton tb2 = new ToggleButton("B");
    tb2.setToggleGroup(group);
    tb2.setUserData(Color.LIGHTBLUE);
    ToggleButton tb3 = new ToggleButton("C");
    tb3.setToggleGroup(group);
    tb3.setUserData(Color.SALMON);

    HBox hbox = new HBox();

    hbox.getChildren().add(tb1);
    hbox.getChildren().add(tb2);
    hbox.getChildren().add(tb3);

    ((Group) scene.getRoot()).getChildren().add(hbox);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Toggle Button Sample");
    stage.setWidth(250);//from   w  w w .ja  v a2  s  .  co  m
    stage.setHeight(180);

    final ToggleGroup group = new ToggleGroup();

    group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        public void changed(ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle) {
            System.out.println((Color) group.getSelectedToggle().getUserData());
        }
    });
    Node rootIcon = new ImageView(new Image(getClass().getResourceAsStream("root.png")));
    ToggleButton tb1 = new ToggleButton("A", rootIcon);
    System.out.println(tb1.toggleGroupProperty());

    tb1.setToggleGroup(group);
    tb1.setUserData(Color.LIGHTGREEN);
    tb1.setSelected(true);

    ToggleButton tb2 = new ToggleButton("B");
    tb2.setToggleGroup(group);
    tb2.setUserData(Color.LIGHTBLUE);
    ToggleButton tb3 = new ToggleButton("C");
    tb3.setToggleGroup(group);
    tb3.setUserData(Color.SALMON);

    System.out.println(tb3.getToggleGroup());

    HBox hbox = new HBox();

    hbox.getChildren().add(tb1);
    hbox.getChildren().add(tb2);
    hbox.getChildren().add(tb3);

    ((Group) scene.getRoot()).getChildren().add(hbox);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Toggle Button Sample");
    stage.setWidth(250);//from  w ww  .  j a v  a  2 s .c  om
    stage.setHeight(180);

    final ToggleGroup group = new ToggleGroup();

    group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        public void changed(ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle) {
            System.out.println((Color) group.getSelectedToggle().getUserData());
        }
    });
    Node rootIcon = new ImageView(new Image(getClass().getResourceAsStream("root.png")));
    ToggleButton tb1 = new ToggleButton("A", rootIcon);
    System.out.println(tb1.toggleGroupProperty());

    tb1.setToggleGroup(group);
    tb1.setUserData(Color.LIGHTGREEN);
    tb1.setSelected(true);

    ToggleButton tb2 = new ToggleButton("B");
    tb2.setToggleGroup(group);
    tb2.setUserData(Color.LIGHTBLUE);
    ToggleButton tb3 = new ToggleButton("C");
    tb3.setToggleGroup(group);
    tb3.setUserData(Color.SALMON);

    tb3.fire();

    HBox hbox = new HBox();

    hbox.getChildren().add(tb1);
    hbox.getChildren().add(tb2);
    hbox.getChildren().add(tb3);

    ((Group) scene.getRoot()).getChildren().add(hbox);
    stage.setScene(scene);
    stage.show();
}

From source file:cz.lbenda.gui.tableView.FilterMenuItem.java

/** Prepare buttons to button bar */
private void prepareBars() {
    ToggleButton sortAsc = new ToggleButton(msgSortAsc,
            IconFactory.getInstance().imageView(this, ICON_SORT_ASC, IconFactory.IconLocation.LOCAL_TOOLBAR));
    ToggleButton sortDsc = new ToggleButton(msgSortDsc,
            IconFactory.getInstance().imageView(this, ICON_SORT_DSC, IconFactory.IconLocation.LOCAL_TOOLBAR));

    //noinspection unchecked
    final StringConverter converter = filterableTableView.stringConverter(tableColumn);

    comparatorAsc = (o1, o2) -> {/*from www .  j  av a2  s. c om*/
        //noinspection unchecked
        Object value1 = filterableTableView.valueForColumn(o1, tableColumn);
        //noinspection unchecked
        Object value2 = filterableTableView.valueForColumn(o2, tableColumn);
        if (value1 == null) {
            if (value2 == null) {
                return 0;
            } else {
                return 1;
            }
        } else if (value2 == null) {
            return -1;
        }
        if (value1 instanceof Comparable) {
            //noinspection unchecked
            return ((Comparable) value1).compareTo(value2);
        }
        //noinspection unchecked
        return converter.toString(value1).compareTo(converter.toString(value2));
    };
    comparatorDsc = comparatorAsc.reversed();

    sortToggleGroup.getToggles().addAll(sortAsc, sortDsc);

    sortAsc.setOnAction(event -> {
        Toggle tg = sortToggleGroup.getSelectedToggle();
        if (tg == sortDsc) {
            //noinspection unchecked
            filterableTableView.sortProperty().setValue(comparatorDsc);
        } else if (tg == sortAsc) {
            //noinspection unchecked
            filterableTableView.sortProperty().setValue(comparatorAsc);
        } else {
            //noinspection unchecked
            filterableTableView.sortProperty().setValue(null);
        }
    });
    sortDsc.setOnAction(sortAsc.getOnAction());
    buttonBar.getChildren().addAll(sortAsc, sortDsc);
}

From source file:eu.over9000.skadi.ui.MainWindow.java

private void setupToolbar(final Stage stage) {

    this.add = GlyphsDude.createIconButton(FontAwesomeIcons.PLUS);
    this.addName = new TextField();
    this.addName.setOnAction(event -> this.add.fire());

    this.add.setOnAction(event -> {
        final String name = this.addName.getText().trim();

        if (name.isEmpty()) {
            return;
        }//from  w  ww . j  a va2 s .  co m

        final boolean result = this.channelHandler.addChannel(name, this.sb);

        if (result) {
            this.addName.clear();
        }

    });

    this.imprt = GlyphsDude.createIconButton(FontAwesomeIcons.DOWNLOAD);
    this.imprt.setOnAction(event -> {
        final TextInputDialog dialog = new TextInputDialog();
        dialog.initModality(Modality.APPLICATION_MODAL);
        dialog.initOwner(stage);
        dialog.setTitle("Import followed channels");
        dialog.setHeaderText("Import followed channels from Twitch");
        dialog.setGraphic(null);
        dialog.setContentText("Twitch username:");

        dialog.showAndWait().ifPresent(name -> {
            final ImportFollowedService ifs = new ImportFollowedService(this.channelHandler, name, this.sb);
            ifs.start();
        });
    });

    this.details = GlyphsDude.createIconButton(FontAwesomeIcons.INFO);
    this.details.setDisable(true);
    this.details.setOnAction(event -> {
        this.detailChannel.set(this.table.getSelectionModel().getSelectedItem());
        if (!this.sp.getItems().contains(this.detailPane)) {
            this.sp.getItems().add(this.detailPane);
            this.doDetailSlide(true);
        }
    });
    this.details.setTooltip(new Tooltip("Show channel information"));

    this.remove = GlyphsDude.createIconButton(FontAwesomeIcons.TRASH);
    this.remove.setDisable(true);
    this.remove.setOnAction(event -> {
        final Channel candidate = this.table.getSelectionModel().getSelectedItem();

        final Alert alert = new Alert(AlertType.CONFIRMATION);
        alert.initModality(Modality.APPLICATION_MODAL);
        alert.initOwner(stage);
        alert.setTitle("Delete channel");
        alert.setHeaderText("Delete " + candidate.getName());
        alert.setContentText("Do you really want to delete " + candidate.getName() + "?");

        final Optional<ButtonType> result = alert.showAndWait();
        if (result.get() == ButtonType.OK) {
            this.channelHandler.getChannels().remove(candidate);
            this.sb.setText("Removed channel " + candidate.getName());
        }
    });

    this.refresh = GlyphsDude.createIconButton(FontAwesomeIcons.REFRESH);
    this.refresh.setTooltip(new Tooltip("Refresh all channels"));
    this.refresh.setOnAction(event -> {
        this.refresh.setDisable(true);
        final ForcedChannelUpdateService service = new ForcedChannelUpdateService(this.channelHandler, this.sb,
                this.refresh);
        service.start();
    });

    this.settings = GlyphsDude.createIconButton(FontAwesomeIcons.COG);
    this.settings.setTooltip(new Tooltip("Settings"));
    this.settings.setOnAction(event -> {
        final SettingsDialog dialog = new SettingsDialog();
        dialog.initModality(Modality.APPLICATION_MODAL);
        dialog.initOwner(stage);
        final Optional<StateContainer> result = dialog.showAndWait();
        if (result.isPresent()) {
            this.persistenceHandler.saveState(result.get());
        }
    });

    this.onlineOnly = new ToggleButton("Live", GlyphsDude.createIcon(FontAwesomeIcons.FILTER));
    this.onlineOnly.setSelected(this.currentState.isOnlineFilterActive());

    this.onlineOnly.setOnAction(event -> {
        this.currentState.setOnlineFilterActive(this.onlineOnly.isSelected());
        this.persistenceHandler.saveState(this.currentState);
        this.updateFilterPredicate();
    });
    // TODO re-enable if 8u60 is released
    this.onlineOnly.setDisable(true);

    this.filterText = new TextField();
    this.filterText.textProperty().addListener((obs, oldV, newV) -> this.updateFilterPredicate());
    this.filterText.setTooltip(new Tooltip("Filter channels by name, status and game"));

    // TODO re-enable if 8u60 is released
    this.filterText.setDisable(true);

    this.tb = new ToolBar();
    this.tb.getItems().addAll(this.addName, this.add, this.imprt, new Separator(), this.refresh, this.settings,
            new Separator(), this.onlineOnly, this.filterText, new Separator(), this.details, this.remove);

    this.chatAndStreamButton = new HandlerControlButton(this.chatHandler, this.streamHandler, this.table,
            this.tb, this.sb);

    this.updateFilterPredicate();
}