List of usage examples for javafx.scene Group Group
public Group()
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("Tabs"); Group root = new Group(); Scene scene = new Scene(root, 400, 250, Color.WHITE); TabPane tabPane = new TabPane(); BorderPane borderPane = new BorderPane(); for (int i = 0; i < 5; i++) { Tab tab = new Tab(); tab.setText("Tab" + i); HBox hbox = new HBox(); hbox.getChildren().add(new Label("Tab" + i)); hbox.setAlignment(Pos.CENTER);// w w w .j av a2s .c o m tab.setContent(hbox); tabPane.getTabs().add(tab); } // bind to take available space borderPane.prefHeightProperty().bind(scene.heightProperty()); borderPane.prefWidthProperty().bind(scene.widthProperty()); borderPane.setCenter(tabPane); root.getChildren().add(borderPane); primaryStage.setScene(scene); primaryStage.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);//from w w w. ja va2 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("Tabs"); Group root = new Group(); Scene scene = new Scene(root, 400, 250, Color.WHITE); TabPane tabPane = new TabPane(); BorderPane borderPane = new BorderPane(); for (int i = 0; i < 5; i++) { Tab tab = new Tab(); tab.setText("Tab" + i); HBox hbox = new HBox(); hbox.getChildren().add(new Label("Tab" + i)); hbox.setAlignment(Pos.CENTER);/*from ww w. j av a 2 s.c o m*/ tab.setContent(hbox); tabPane.getTabs().add(tab); } tabPane.setSide(Side.LEFT); //tabPane.setSide(Side.TOP); //tabPane.setSide(Side.RIGHT); //tabPane.setSide(Side.BOTTOM); // bind to take available space borderPane.prefHeightProperty().bind(scene.heightProperty()); borderPane.prefWidthProperty().bind(scene.widthProperty()); borderPane.setCenter(tabPane); root.getChildren().add(borderPane); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { WebEngine webEngine = new WebEngine(); webEngine.getLoadWorker().stateProperty().addListener((obs, oldValue, newValue) -> { if (newValue == Worker.State.SUCCEEDED) { JSObject jsobj = (JSObject) webEngine.executeScript("window"); jsobj.setMember("ABCD", new HelloWorld()); }// ww w . j ava 2s.c o m }); webEngine.load("http://www.java2s.com"); Group root = new Group(); Scene scene = new Scene(root, 300, 250); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("Keyboard"); Group root = new Group(); Scene scene = new Scene(root, 530, 300, Color.WHITE); MenuBar menuBar = new MenuBar(); menuBar.prefWidthProperty().bind(primaryStage.widthProperty()); root.getChildren().add(menuBar);/*from w w w .j a v a2s. c om*/ Menu menu = new Menu("File"); menuBar.getMenus().add(menu); MenuItem newItem = MenuItemBuilder.create().text("New") .accelerator(new KeyCodeCombination(KeyCode.N, KeyCombination.CONTROL_DOWN)) .onAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { System.out.println("Ctrl-N"); } }).build(); menu.getItems().add(newItem); MenuItem saveItem = MenuItemBuilder.create().text("Save") .accelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN)) .onAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { System.out.println("Ctrl-S"); } }).build(); menu.getItems().add(saveItem); menu.getItems().add(new SeparatorMenuItem()); MenuItem exitItem = MenuItemBuilder.create().text("Exit") .accelerator(new KeyCodeCombination(KeyCode.X, KeyCombination.CONTROL_DOWN)) .onAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { System.out.println("Ctrl-X"); } }).build(); menu.getItems().add(exitItem); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group()); scene.setFill(Color.ALICEBLUE); stage.setScene(scene);/* w ww . j a v a 2 s . co m*/ stage.show(); stage.setWidth(300); stage.setHeight(200); label.setStyle("-fx-font: 25 arial;"); label.setLayoutX(40); rect.setStroke(Color.BLUE); rect.setStrokeWidth(3); rect.setFill(Color.WHITE); final String[] greetings = new String[] { "A", "B", "C", "D", "E" }; final ChoiceBox<String> cb = new ChoiceBox<String>( FXCollections.observableArrayList("a", "b", "c", "d", "e")); cb.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() { public void changed(ObservableValue ov, Number value, Number new_value) { label.setText(greetings[new_value.intValue()]); } }); cb.setTooltip(new Tooltip("Select the language")); cb.setValue("English"); HBox hb = new HBox(); hb.getChildren().addAll(cb, label); 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
@Override public void start(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 330, 120, Color.WHITE); BorderPane mainPane = new BorderPane(); root.getChildren().add(mainPane);/* w ww. j a va 2 s . c o m*/ final Label label = new Label("Files Transfer:"); final ProgressBar progressBar = new ProgressBar(0); final HBox hb = new HBox(); hb.setSpacing(5); hb.setAlignment(Pos.CENTER); hb.getChildren().addAll(label, progressBar); mainPane.setTop(hb); final Button startButton = new Button("Start"); final Button cancelButton = new Button("Cancel"); final HBox hb2 = new HBox(); hb2.setSpacing(5); hb2.setAlignment(Pos.CENTER); hb2.getChildren().addAll(startButton, cancelButton); mainPane.setBottom(hb2); startButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(true); progressBar.setProgress(0); cancelButton.setDisable(false); copyWorker = createWorker(); progressBar.progressProperty().unbind(); progressBar.progressProperty().bind(copyWorker.progressProperty()); copyWorker.messageProperty().addListener(new ChangeListener<String>() { public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { System.out.println(newValue); } }); new Thread(copyWorker).start(); } }); cancelButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(false); cancelButton.setDisable(true); copyWorker.cancel(true); progressBar.progressProperty().unbind(); progressBar.setProgress(0); System.out.println("cancelled."); } }); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 330, 120, Color.WHITE); BorderPane mainPane = new BorderPane(); root.getChildren().add(mainPane);/*from w w w . j a v a 2 s . co m*/ final Label label = new Label("Files Transfer:"); final ProgressBar progressBar = new ProgressBar(0); final HBox hb = new HBox(); hb.setSpacing(5); hb.setAlignment(Pos.CENTER); hb.getChildren().addAll(label, progressBar); mainPane.setTop(hb); final Button startButton = new Button("Start"); final Button cancelButton = new Button("Cancel"); final HBox hb2 = new HBox(); hb2.setSpacing(5); hb2.setAlignment(Pos.CENTER); hb2.getChildren().addAll(startButton, cancelButton); mainPane.setBottom(hb2); startButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(true); progressBar.setProgress(0); cancelButton.setDisable(false); copyWorker = createWorker(); progressBar.progressProperty().unbind(); progressBar.progressProperty().bind(copyWorker.progressProperty()); copyWorker.messageProperty().addListener(new ChangeListener<String>() { public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { System.out.println(newValue); } }); new Thread(copyWorker).start(); } }); cancelButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(false); cancelButton.setDisable(true); copyWorker.cancel(true); progressBar.progressProperty().unbind(); progressBar.setProgress(0); System.out.println("cancelled."); } }); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 300, 250); Rectangle rect = new Rectangle(); rect.setWidth(100);/*from w ww.j av a2s . c om*/ rect.setHeight(100); root.getChildren().add(rect); rect.setOnScroll(new EventHandler<ScrollEvent>() { @Override public void handle(ScrollEvent event) { if (!event.isInertia()) { rect.setTranslateX(rect.getTranslateX() + event.getDeltaX()); rect.setTranslateY(rect.getTranslateY() + event.getDeltaY()); } System.out.println("Rectangle: Scroll event" + ", inertia: " + event.isInertia() + ", direct: " + event.isDirect()); event.consume(); } }); rect.setOnScrollStarted(new EventHandler<ScrollEvent>() { @Override public void handle(ScrollEvent event) { System.out.println("Rectangle: Scroll started event"); event.consume(); } }); rect.setOnScrollFinished(new EventHandler<ScrollEvent>() { @Override public void handle(ScrollEvent event) { System.out.println("Rectangle: Scroll finished event"); event.consume(); } }); rect.setOnZoom(new EventHandler<ZoomEvent>() { @Override public void handle(ZoomEvent event) { rect.setScaleX(rect.getScaleX() * event.getZoomFactor()); rect.setScaleY(rect.getScaleY() * event.getZoomFactor()); System.out.println("Rectangle: Zoom event" + ", inertia: " + event.isInertia() + ", direct: " + event.isDirect()); event.consume(); } }); rect.setOnZoomStarted(new EventHandler<ZoomEvent>() { @Override public void handle(ZoomEvent event) { System.out.println("Rectangle: Zoom event started"); event.consume(); } }); rect.setOnZoomFinished(new EventHandler<ZoomEvent>() { @Override public void handle(ZoomEvent event) { System.out.println("Rectangle: Zoom event finished"); event.consume(); } }); rect.setOnRotate(new EventHandler<RotateEvent>() { @Override public void handle(RotateEvent event) { rect.setRotate(rect.getRotate() + event.getAngle()); System.out.println("Rectangle: Rotate event" + ", inertia: " + event.isInertia() + ", direct: " + event.isDirect()); event.consume(); } }); rect.setOnRotationStarted(new EventHandler<RotateEvent>() { @Override public void handle(RotateEvent event) { System.out.println("Rectangle: Rotate event started"); event.consume(); } }); rect.setOnRotationFinished(new EventHandler<RotateEvent>() { @Override public void handle(RotateEvent event) { System.out.println("Rectangle: Rotate event finished"); event.consume(); } }); rect.setOnSwipeRight(new EventHandler<SwipeEvent>() { @Override public void handle(SwipeEvent event) { System.out.println("Rectangle: Swipe right event"); event.consume(); } }); rect.setOnSwipeLeft(new EventHandler<SwipeEvent>() { @Override public void handle(SwipeEvent event) { System.out.println("Rectangle: Swipe left event"); event.consume(); } }); rect.setOnTouchPressed(new EventHandler<TouchEvent>() { @Override public void handle(TouchEvent event) { System.out.println("Rectangle: Touch pressed event"); event.consume(); } }); rect.setOnTouchReleased(new EventHandler<TouchEvent>() { @Override public void handle(TouchEvent event) { System.out.println("Rectangle: Touch released event"); event.consume(); } }); rect.setOnMousePressed(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { if (event.isSynthesized()) { System.out.println( "Ellipse: Mouse pressed event from touch" + ", synthesized: " + event.isSynthesized()); } event.consume(); } }); rect.setOnMouseReleased(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { if (event.isSynthesized()) { System.out.println( "Ellipse: Mouse released event from touch" + ", synthesized: " + event.isSynthesized()); } event.consume(); } }); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { WebEngine webEngine = new WebEngine(); webEngine.getLoadWorker().stateProperty().addListener((obs, oldValue, newValue) -> { System.out.println(newValue); if (newValue == State.SUCCEEDED) { System.out.println("finished loading"); String html = (String) webEngine.executeScript("document.documentElement.outerHTML"); System.out.println(html); }/*from ww w . j a va2 s. c o m*/ }); webEngine.load("http://www.java2s.com"); Group root = new Group(); Scene scene = new Scene(root, 300, 250); primaryStage.setScene(scene); primaryStage.show(); }