List of usage examples for javafx.scene.layout GridPane setHgap
public final void setHgap(double value)
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group(), 450, 250); TextField notification = new TextField(); MenuItem item1 = new MenuItem("About"); item1.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("About"); }//from w w w . j a va 2 s . c o m }); MenuItem item2 = new MenuItem("Preferences"); item2.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("Preferences"); } }); final ContextMenu contextMenu = new ContextMenu(item1, item2); contextMenu.setOnShowing(new EventHandler<WindowEvent>() { public void handle(WindowEvent e) { System.out.println("showing"); } }); contextMenu.setOnShown(new EventHandler<WindowEvent>() { public void handle(WindowEvent e) { System.out.println("shown"); } }); System.out.println(contextMenu.onActionProperty()); contextMenu.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("on"); } }); notification.setContextMenu(contextMenu); GridPane grid = new GridPane(); grid.setVgap(4); grid.setHgap(10); grid.setPadding(new Insets(5, 5, 5, 5)); grid.add(new Label("To: "), 0, 0); grid.add(notification, 1, 0); contextMenu.show(grid, Side.BOTTOM, 20, 20); Group root = (Group) scene.getRoot(); root.getChildren().add(grid); stage.setScene(scene); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { stage.setTitle("ComboBoxSample"); Scene scene = new Scene(new Group(), 450, 250); ComboBox emailComboBox = new ComboBox(); emailComboBox.getItems().addAll("A", "B", "C", "D", "E"); emailComboBox.setCellFactory(new Callback<ListView<String>, ListCell<String>>() { @Override/* w ww . j av a 2 s . com*/ public ListCell<String> call(ListView<String> param) { final ListCell<String> cell = new ListCell<String>() { { super.setPrefWidth(100); } @Override public void updateItem(String item, boolean empty) { super.updateItem(item, empty); if (item != null) { setText(item); if (item.contains("A")) { setTextFill(Color.RED); } else if (item.contains("B")) { setTextFill(Color.GREEN); } else { setTextFill(Color.BLACK); } } else { setText(null); } } }; return cell; } }); GridPane grid = new GridPane(); grid.setVgap(4); grid.setHgap(10); grid.setPadding(new Insets(5, 5, 5, 5)); grid.add(new Label("To: "), 0, 0); grid.add(emailComboBox, 1, 0); Group root = (Group) scene.getRoot(); root.getChildren().add(grid); stage.setScene(scene); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { Group root = new Group(); Scene scene = new Scene(root, 500, 200); stage.setScene(scene);/*from w w w .java 2 s . com*/ GridPane grid = new GridPane(); grid.setPadding(new Insets(10, 10, 10, 10)); grid.setVgap(2); grid.setHgap(5); scene.setRoot(grid); caption.setFont(Font.font("Verdana", 20)); GridPane.setConstraints(caption, 0, 0); GridPane.setColumnSpan(caption, 8); grid.getChildren().add(caption); final Separator sepHor = new Separator(); sepHor.setValignment(VPos.CENTER); GridPane.setConstraints(sepHor, 0, 1); GridPane.setColumnSpan(sepHor, 7); grid.getChildren().add(sepHor); stage.show(); }
From source file:Main.java
public MyDialog(Stage owner) { super();// w ww . j a v a 2 s .c o m initOwner(owner); setTitle("title"); Group root = new Group(); Scene scene = new Scene(root, 250, 150, Color.WHITE); setScene(scene); GridPane gridpane = new GridPane(); gridpane.setPadding(new Insets(5)); gridpane.setHgap(5); gridpane.setVgap(5); Label userNameLbl = new Label("User Name: "); gridpane.add(userNameLbl, 0, 1); Label passwordLbl = new Label("Password: "); gridpane.add(passwordLbl, 0, 2); final TextField userNameFld = new TextField("Admin"); gridpane.add(userNameFld, 1, 1); final PasswordField passwordFld = new PasswordField(); passwordFld.setText("password"); gridpane.add(passwordFld, 1, 2); Button login = new Button("Change"); login.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { close(); } }); gridpane.add(login, 1, 3); GridPane.setHalignment(login, HPos.RIGHT); root.getChildren().add(gridpane); }
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);//from ww w . j a va 2s.c o m 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
private GridPane createGridPane() { GridPane gridpane = new GridPane(); gridpane.setPadding(new Insets(5)); gridpane.setHgap(5); gridpane.setVgap(5);/*ww w . j a va2s . co m*/ ColumnConstraints column1 = new ColumnConstraints(100); ColumnConstraints column2 = new ColumnConstraints(50, 150, 300); column2.setHgrow(Priority.ALWAYS); gridpane.getColumnConstraints().addAll(column1, column2); Label fNameLbl = new Label("First Name"); TextField fNameFld = new TextField(); Label lNameLbl = new Label("Last Name"); TextField lNameFld = new TextField(); Button saveButton = new Button("Save"); GridPane.setHalignment(fNameLbl, HPos.RIGHT); GridPane.setHalignment(lNameLbl, HPos.RIGHT); GridPane.setHalignment(fNameFld, HPos.LEFT); GridPane.setHalignment(lNameFld, HPos.LEFT); GridPane.setHalignment(saveButton, HPos.RIGHT); gridpane.add(fNameLbl, 0, 0); gridpane.add(fNameFld, 1, 0); gridpane.add(lNameLbl, 0, 1); gridpane.add(lNameFld, 1, 1); gridpane.add(saveButton, 1, 2); return gridpane; }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("JavaFX Welcome"); GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER);//from w w w . j a v a2s . c om grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); Text scenetitle = new Text("Welcome"); scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20)); grid.add(scenetitle, 0, 0, 2, 1); Label userName = new Label("User Name:"); grid.add(userName, 0, 1); TextField userTextField = new TextField(); grid.add(userTextField, 1, 1); Label pw = new Label("Password:"); grid.add(pw, 0, 2); PasswordField pwBox = new PasswordField(); grid.add(pwBox, 1, 2); Button btn = new Button("Sign in"); HBox hbBtn = new HBox(10); hbBtn.setAlignment(Pos.BOTTOM_RIGHT); hbBtn.getChildren().add(btn); grid.add(hbBtn, 1, 4); final Text actiontarget = new Text(); grid.add(actiontarget, 1, 6); btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { actiontarget.setFill(Color.FIREBRICK); actiontarget.setText("Sign in button pressed"); } }); Scene scene = new Scene(grid, 300, 275); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { BorderPane root = new BorderPane(); Scene scene = new Scene(root, 400, 250, Color.WHITE); GridPane gridpane = new GridPane(); gridpane.setPadding(new Insets(5)); gridpane.setHgap(10); gridpane.setVgap(10);//from ww w .j a v a2 s . c o m ColumnConstraints column1 = new ColumnConstraints(150, 150, Double.MAX_VALUE); ColumnConstraints column2 = new ColumnConstraints(50); ColumnConstraints column3 = new ColumnConstraints(150, 150, Double.MAX_VALUE); column1.setHgrow(Priority.ALWAYS); column3.setHgrow(Priority.ALWAYS); gridpane.getColumnConstraints().addAll(column1, column2, column3); Label candidatesLbl = new Label("Candidates"); GridPane.setHalignment(candidatesLbl, HPos.CENTER); gridpane.add(candidatesLbl, 0, 0); Label selectedLbl = new Label("selected"); gridpane.add(selectedLbl, 2, 0); GridPane.setHalignment(selectedLbl, HPos.CENTER); // Candidates final ObservableList<String> candidates = FXCollections.observableArrayList("Z", "A", "B", "C", "D"); final ListView<String> candidatesListView = new ListView<>(candidates); gridpane.add(candidatesListView, 0, 1); final ObservableList<String> selected = FXCollections.observableArrayList(); final ListView<String> heroListView = new ListView<>(selected); gridpane.add(heroListView, 2, 1); Button sendRightButton = new Button(" > "); sendRightButton.setOnAction((ActionEvent event) -> { String potential = candidatesListView.getSelectionModel().getSelectedItem(); if (potential != null) { candidatesListView.getSelectionModel().clearSelection(); candidates.remove(potential); selected.add(potential); } }); Button sendLeftButton = new Button(" < "); sendLeftButton.setOnAction((ActionEvent event) -> { String s = heroListView.getSelectionModel().getSelectedItem(); if (s != null) { heroListView.getSelectionModel().clearSelection(); selected.remove(s); candidates.add(s); } }); VBox vbox = new VBox(5); vbox.getChildren().addAll(sendRightButton, sendLeftButton); gridpane.add(vbox, 1, 1); root.setCenter(gridpane); GridPane.setVgrow(root, Priority.ALWAYS); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("ObservableLists"); Group root = new Group(); Scene scene = new Scene(root, 400, 250, Color.WHITE); GridPane gridpane = new GridPane(); gridpane.setPadding(new Insets(5)); gridpane.setHgap(10); gridpane.setVgap(10);//from w w w . ja v a2 s. c om Label candidatesLbl = new Label("Left"); GridPane.setHalignment(candidatesLbl, HPos.CENTER); gridpane.add(candidatesLbl, 0, 0); Label heroesLbl = new Label("Right"); gridpane.add(heroesLbl, 2, 0); GridPane.setHalignment(heroesLbl, HPos.CENTER); final ObservableList<String> lefts = FXCollections.observableArrayList("A", "B", "C"); final ListView<String> leftListView = new ListView<String>(lefts); leftListView.setPrefWidth(150); leftListView.setPrefHeight(150); gridpane.add(leftListView, 0, 1); final ObservableList<String> rights = FXCollections.observableArrayList(); final ListView<String> rightListView = new ListView<String>(rights); rightListView.setPrefWidth(150); rightListView.setPrefHeight(150); gridpane.add(rightListView, 2, 1); Button sendRightButton = new Button(">"); sendRightButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { String item = leftListView.getSelectionModel().getSelectedItem(); if (item != null) { leftListView.getSelectionModel().clearSelection(); lefts.remove(item); rights.add(item); } } }); Button sendLeftButton = new Button("<"); sendLeftButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { String item = rightListView.getSelectionModel().getSelectedItem(); if (item != null) { rightListView.getSelectionModel().clearSelection(); rights.remove(item); lefts.add(item); } } }); VBox vbox = new VBox(5); vbox.getChildren().addAll(sendRightButton, sendLeftButton); gridpane.add(vbox, 1, 1); GridPane.setConstraints(vbox, 1, 1, 1, 2, HPos.CENTER, VPos.CENTER); root.getChildren().add(gridpane); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { BorderPane root = new BorderPane(); Scene scene = new Scene(root, 400, 250, Color.WHITE); GridPane gridpane = new GridPane(); gridpane.setPadding(new Insets(5)); gridpane.setHgap(10); gridpane.setVgap(10);/*from www. j a v a2s . co m*/ ColumnConstraints column1 = new ColumnConstraints(150, 150, Double.MAX_VALUE); ColumnConstraints column2 = new ColumnConstraints(50); ColumnConstraints column3 = new ColumnConstraints(150, 150, Double.MAX_VALUE); column1.setHgrow(Priority.ALWAYS); column3.setHgrow(Priority.ALWAYS); gridpane.getColumnConstraints().addAll(column1, column2, column3); // Candidates label Label candidatesLbl = new Label("Candidates"); GridPane.setHalignment(candidatesLbl, HPos.CENTER); gridpane.add(candidatesLbl, 0, 0); // Heroes label Label heroesLbl = new Label("Letters"); gridpane.add(heroesLbl, 2, 0); GridPane.setHalignment(heroesLbl, HPos.CENTER); final ObservableList<String> candidates = FXCollections.observableArrayList("A", "B", "C", "D"); final ListView<String> candidatesListView = new ListView<>(candidates); gridpane.add(candidatesListView, 0, 1); final ObservableList<String> heroes = FXCollections.observableArrayList(); final ListView<String> heroListView = new ListView<>(heroes); gridpane.add(heroListView, 2, 1); Button sendRightButton = new Button(" > "); sendRightButton.setOnAction((ActionEvent event) -> { String potential = candidatesListView.getSelectionModel().getSelectedItem(); if (potential != null) { candidatesListView.getSelectionModel().clearSelection(); candidates.remove(potential); heroes.add(potential); } }); Button sendLeftButton = new Button(" < "); sendLeftButton.setOnAction((ActionEvent event) -> { String notHero = heroListView.getSelectionModel().getSelectedItem(); if (notHero != null) { heroListView.getSelectionModel().clearSelection(); heroes.remove(notHero); candidates.add(notHero); } }); // place the buttons VBox vbox = new VBox(5); vbox.setAlignment(Pos.CENTER); vbox.getChildren().addAll(sendRightButton, sendLeftButton); GridPane.setHalignment(vbox, HPos.CENTER); gridpane.add(vbox, 1, 1); // place the grid root.setCenter(gridpane); GridPane.setVgrow(root, Priority.ALWAYS); primaryStage.setScene(scene); primaryStage.show(); }