List of usage examples for javafx.scene.control ToggleButton setUserData
public void setUserData(Object value)
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 ww w .j a v a 2s .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()); } }); ToggleButton tb1 = new ToggleButton("A"); 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 va 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.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 ww .j a va2 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()); } }); ToggleButton tb1 = new ToggleButton(); tb1.setText("A"); 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 a 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); 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);/*from www. j a v a 2 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.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 ww 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.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 va2 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); 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 w w.j a v a 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.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);//w w w. ja v a 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.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:net.rptools.tokentool.controller.ManageOverlays_Controller.java
private void loadImages(File dir) { // Clear Details panel clearDetails();/* w w w . j a v a2s. c om*/ currentDirectory = dir; File[] files = dir.listFiles(ImageUtil.SUPPORTED_FILENAME_FILTER); Task<Void> task = new Task<Void>() { @Override public Void call() { for (File file : files) { Path filePath = file.toPath(); if (loadOverlaysThread.isInterrupted()) { Platform.runLater(() -> overlayViewFlowPane.getChildren().clear()); break; } try { ToggleButton overlayButton = new ToggleButton(); ImageView imageViewNode = ImageUtil.getOverlayThumb(new ImageView(), filePath); overlayButton.getStyleClass().add("overlay-toggle-button"); overlayButton.setGraphic(imageViewNode); overlayButton.setUserData(file); overlayButton.setToggleGroup(overlayToggleGroup); overlayButton.addEventHandler(ActionEvent.ACTION, event -> { // No modifier keys used so add toggle group back to all buttons resetToggleGroup(); // Also set button to selected due to resetting toggle groups & no unselecting needed, makes for better interface IMO overlayButton.setSelected(true); // Update the Details panel with the last selected overlay File overlayFile = (File) overlayButton.getUserData(); updateDetails(overlayFile, (ImageView) overlayButton.getGraphic(), overlayButton.isSelected()); // Consume the event, no more logic needed event.consume(); }); overlayButton.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { // Allow multiple selections if shortcutKey+left_mouse is pressed if (event.getButton().equals(MouseButton.PRIMARY) && event.isShortcutDown()) { // Update the Details panel with the last selected overlay File overlayFile = (File) overlayButton.getUserData(); updateDetails(overlayFile, (ImageView) overlayButton.getGraphic(), true); // Remove the toggle group to allow multiple toggle button selection overlayButton.setToggleGroup(null); // Select the button overlayButton.setSelected(true); // Consume the event, no more logic needed event.consume(); } } }); Platform.runLater(() -> overlayViewFlowPane.getChildren().add(overlayButton)); } catch (IOException e) { log.error("Loading image: " + filePath.getFileName(), e); } } return null; } }; loadOverlaysThread.interrupt(); executorService.execute(task); }