List of usage examples for javafx.beans.value ChangeListener ChangeListener
ChangeListener
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);//ww w. j a va 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.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 ww w. java2 s . com*/ 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:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group()); stage.setScene(scene);/*from w ww . ja va 2 s . c o m*/ stage.show(); stage.setWidth(300); stage.setHeight(200); final String[] greetings = new String[] { "Hello", "Hola", "1", "2" }; final ChoiceBox cb = new ChoiceBox(FXCollections.observableArrayList("1", "2", "3", "4")); cb.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() { public void changed(ObservableValue ov, Number value, Number new_value) { System.out.println(new_value.intValue()); } }); cb.setValue("2"); HBox hb = new HBox(); hb.getChildren().addAll(cb); hb.setSpacing(30); hb.setAlignment(Pos.CENTER); hb.setPadding(new Insets(10, 0, 0, 10)); ((Group) scene.getRoot()).getChildren().add(hb); }
From source file:Main.java
License:asdf
@Override public void start(final Stage stage) { stage.setTitle("HTML"); stage.setWidth(500);// w ww .j a v a 2 s . c om stage.setHeight(500); Scene scene = new Scene(new Group()); VBox root = new VBox(); final WebView browser = new WebView(); final WebEngine webEngine = browser.getEngine(); ScrollPane scrollPane = new ScrollPane(); scrollPane.setContent(browser); webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() { @Override public void changed(ObservableValue ov, State oldState, State newState) { if (newState == Worker.State.SUCCEEDED) { stage.setTitle(webEngine.getLocation()); System.out.println("called"); } } }); webEngine.load("http://javafx.com"); webEngine.loadContent("<b>asdf</b>"); root.getChildren().addAll(scrollPane); scene.setRoot(root); stage.setScene(scene); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group()); stage.setTitle("Tooltip Sample"); stage.setWidth(300);/*from w ww . java 2 s . co m*/ stage.setHeight(150); final CheckBox cb = new CheckBox("checkBox"); final Tooltip tooltip = new Tooltip("$ tooltip"); tooltip.setFont(new Font("Arial", 16)); cb.setTooltip(tooltip); cb.selectedProperty().addListener(new ChangeListener<Boolean>() { public void changed(ObservableValue<? extends Boolean> ov, Boolean old_val, Boolean new_val) { System.out.println(cb.isSelected()); } }); ((Group) scene.getRoot()).getChildren().add(cb); stage.setScene(scene); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group()); stage.setTitle("Checkbox Sample"); stage.setWidth(230);/* www . j a v a2 s . co m*/ stage.setHeight(120); for (int i = 0; i < names.length; i++) { final CheckBox cb = cbs[i] = new CheckBox(names[i]); cb.selectedProperty().addListener(new ChangeListener<Boolean>() { public void changed(ObservableValue ov, Boolean old_val, Boolean new_val) { System.out.println(new_val); } }); } VBox vbox = new VBox(); vbox.getChildren().addAll(cbs); vbox.setSpacing(5); HBox hbox = new HBox(); hbox.setPadding(new Insets(0, 0, 0, 5)); StackPane stack = new StackPane(); stack.getChildren().add(hbox); HBox root = new HBox(); root.getChildren().add(vbox); root.getChildren().add(stack); root.setSpacing(40); root.setPadding(new Insets(20, 10, 10, 20)); ((Group) scene.getRoot()).getChildren().add(root); stage.setScene(scene); stage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("Menus"); Group root = new Group(); Scene scene = new Scene(root, 300, 250, Color.WHITE); MenuBar menuBar = new MenuBar(); Menu tools = new Menu("Your Menu"); Image image = new Image(getClass().getResourceAsStream("a.png")); CheckMenuItem item = new CheckMenuItem("Item 1", new ImageView(image)); tools.getItems().add(item);/* w w w .ja va2s. c o m*/ item.selectedProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue arg0, Object arg1, Object arg2) { } }); tools.getItems().add(CheckMenuItemBuilder.create().text("Item 2").selected(true).build()); menuBar.getMenus().add(tools); menuBar.prefWidthProperty().bind(primaryStage.widthProperty()); root.getChildren().add(menuBar); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { Group root = new Group(); Scene scene = new Scene(root, 600, 400); stage.setScene(scene);/*w ww . ja v a 2 s .c om*/ stage.setTitle("Slider Sample"); GridPane grid = new GridPane(); grid.setPadding(new Insets(10, 10, 10, 10)); grid.setVgap(10); grid.setHgap(70); scene.setRoot(grid); GridPane.setConstraints(opacityCaption, 0, 1); grid.getChildren().add(opacityCaption); opacityLevel.valueProperty().addListener(new ChangeListener<Number>() { public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) { System.out.println(new_val.doubleValue()); opacityValue.setText(String.format("%.2f", new_val)); } }); GridPane.setConstraints(opacityLevel, 1, 1); grid.getChildren().add(opacityLevel); GridPane.setConstraints(opacityValue, 2, 1); grid.getChildren().add(opacityValue); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group()); stage.setWidth(250);/*from w w w . j a v a 2s . c o m*/ stage.setHeight(150); final ToggleGroup group = new ToggleGroup(); RadioButton rb1 = new RadioButton("A"); rb1.setToggleGroup(group); rb1.setUserData("A"); RadioButton rb2 = new RadioButton("B"); rb2.setToggleGroup(group); rb2.setUserData("B"); RadioButton rb3 = new RadioButton("C"); rb3.setToggleGroup(group); rb3.setUserData("C"); group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() { public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) { if (group.getSelectedToggle() != null) { System.out.println(group.getSelectedToggle().getUserData().toString()); } } }); HBox hbox = new HBox(); VBox vbox = new VBox(); vbox.getChildren().add(rb1); vbox.getChildren().add(rb2); vbox.getChildren().add(rb3); vbox.setSpacing(10); hbox.getChildren().add(vbox); hbox.setSpacing(50); hbox.setPadding(new Insets(20, 10, 10, 20)); ((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("Radio Button Sample"); stage.setWidth(250);/*from w w w . j av a 2 s. c o m*/ stage.setHeight(150); final ToggleGroup group = new ToggleGroup(); RadioButton rb1 = new RadioButton("A"); rb1.setToggleGroup(group); rb1.setUserData("A"); RadioButton rb2 = new RadioButton("B"); rb2.setToggleGroup(group); rb2.setUserData("B"); RadioButton rb3 = new RadioButton("C"); rb3.setToggleGroup(group); rb3.setUserData("C"); group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() { public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) { if (group.getSelectedToggle() != null) { System.out.println(group.getSelectedToggle().getUserData().toString()); } } }); HBox hbox = new HBox(); VBox vbox = new VBox(); vbox.getChildren().add(rb1); vbox.getChildren().add(rb2); vbox.getChildren().add(rb3); vbox.setSpacing(10); hbox.getChildren().add(vbox); hbox.setSpacing(50); hbox.setPadding(new Insets(20, 10, 10, 20)); ((Group) scene.getRoot()).getChildren().add(hbox); stage.setScene(scene); stage.show(); }