void updateContentGrid() { contentGrid.getColumnConstraints().clear(); contentGrid.getChildren().clear(); int colsNumber = daysPerWeek + (datePicker.isShowWeekNumbers() ? 1 : 0); ColumnConstraints columnConstraints = new ColumnConstraints(); columnConstraints.setPercentWidth(100); for (int i = 0; i < colsNumber; i++) { contentGrid.getColumnConstraints().add(columnConstraints); } // Week days cells for (int i = 0; i < daysPerWeek; i++) { contentGrid.add(weekDaysCells.get(i), i + colsNumber - daysPerWeek, 1); } // Week number cells if (datePicker.isShowWeekNumbers()) { for (int i = 0; i < 6; i++) { contentGrid.add(weekNumberCells.get(i), 0, i + 2); } } // Month days cells for (int row = 0; row < 6; row++) { for (int col = 0; col < daysPerWeek; col++) { contentGrid.add(dayCells.get(row * daysPerWeek + col), col + colsNumber - daysPerWeek, row + 2); } } }
BaseInfoTab() { setClosable(false); grid.getStyleClass().add("info-props"); grid.setAlignment(Pos.TOP_CENTER); ColumnConstraints column1 = new ColumnConstraints(); column1.setPercentWidth(25); ColumnConstraints column2 = new ColumnConstraints(); column2.setPercentWidth(75); grid.getColumnConstraints().addAll(column1, column2); ScrollPane scroll = new ScrollPane(grid); scroll.setFitToHeight(true); scroll.setFitToWidth(true); setContent(scroll); }
@Override public void start(Stage primaryStage) throws IOException { GridPane root = new GridPane(); root.getColumnConstraints().addAll(DoubleStream.of(30, 2, 68) .mapToObj(width -> { ColumnConstraints constraints = new ColumnConstraints(); constraints.setPercentWidth(width); constraints.setFillWidth(true); return constraints; }).toArray(ColumnConstraints[]::new)); RowConstraints rowConstraints = new RowConstraints(); rowConstraints.setVgrow(Priority.ALWAYS); root.getRowConstraints().add(rowConstraints); root.addRow(0, Stream.of("red", "green", "blue").map(s -> createRegion(s)).toArray(Node[]::new)); Scene scene = new Scene(root); primaryStage.setScene(scene); primaryStage.show(); }
@Override public void start(Stage primaryStage) throws IOException { GridPane root = new GridPane(); root.getColumnConstraints().addAll(DoubleStream.of(30, 2, 68) .mapToObj(width -> { ColumnConstraints constraints = new ColumnConstraints(); constraints.setPercentWidth(width); constraints.setFillWidth(true); return constraints; }).toArray(ColumnConstraints[]::new)); RowConstraints rowConstraints = new RowConstraints(); rowConstraints.setVgrow(Priority.ALWAYS); root.getRowConstraints().add(rowConstraints); root.addRow(0, Stream.of("red", "green", "blue").map(s -> { Region region = new Region(); region.setStyle("-fx-background-color:"+s); return region; }).toArray(Node[]::new)); Scene scene = new Scene(root); primaryStage.setScene(scene); primaryStage.show(); }
GridPane grid = new GridPane(); /* your code */ ColumnConstraints column1 = new ColumnConstraints(); column1.setPercentWidth(50); grid.getColumnConstraints().add(column1);
@Override public void start(Stage primaryStage) { Text text00 = new Text("text"); Text text01 = new Text("text"); Text text02 = new Text("text"); Text text10 = new Text("text"); Text text11 = new Text("text"); Text text12 = new Text("text"); GridPane gridPane = new GridPane(); ColumnConstraints cConstraints = new ColumnConstraints(); cConstraints.setHalignment(HPos.LEFT); cConstraints.setHgrow(Priority.ALWAYS); gridPane.getColumnConstraints().addAll(cConstraints, cConstraints); gridPane.addColumn(0, text00, text01, text02); gridPane.addColumn(1, text10, text11, text12); GridPane.setHalignment(text11, HPos.CENTER); GridPane.setHalignment(text01, HPos.CENTER); Scene scene = new Scene(gridPane); primaryStage.setScene(scene); primaryStage.show(); }
@Override public void start(Stage primaryStage) { GridPane chat = new GridPane(); chat.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE); ColumnConstraints c1 = new ColumnConstraints(); c1.setPercentWidth(100); chat.getColumnConstraints().add(c1); for (int i = 0; i < 20; i++) { Label chatMessage = new Label("Hi " + i); chatMessage.getStyleClass().add("chat-bubble"); GridPane.setHalignment(chatMessage, i % 2 == 0 ? HPos.LEFT : HPos.RIGHT); chat.addRow(i, chatMessage); } ScrollPane scroll = new ScrollPane(chat); scroll.setFitToWidth(true); Scene scene = new Scene(scroll, 500, 500); scene.getStylesheets().add(getClass().getResource("Test.css").toExternalForm()); primaryStage.setScene(scene); primaryStage.show(); }
@Override public void start(Stage stage) throws Exception { stage.setTitle("Window title"); GridPane grid = new GridPane(); gridSetup(grid); // Building my grid elements here (2 columns) // Setting columns size in percent ColumnConstraints column = new ColumnConstraints(); column.setPercentWidth(30); grid.getColumnConstraints().add(column); column = new ColumnConstraints(); column.setPercentWidth(70); grid.getColumnConstraints().add(column); grid.setPrefSize(WINDOW_WIDTH, WINDOW_HEIGHT); // Default width and height grid.setMaxSize(Region.USE_COMPUTED_SIZE, Region.USE_COMPUTED_SIZE); Scene scene = new Scene(grid, WINDOW_WIDTH, WINDOW_HEIGHT); stage.setScene(scene); stage.show(); }
public void start(Stage stage) { VBox box1 = new VBox(1); VBox box2 = new VBox(1); //random content RectangleBuilder builder = RectangleBuilder.create().width(20).height(20); box1.getChildren().addAll(builder.build(), builder.build(), builder.build()); builder.fill(Color.RED); box2.getChildren().addAll(builder.build(), builder.build(), builder.build()); //half by half screen GridPane grid = new GridPane(); grid.addRow(0, box1, box2); ColumnConstraints halfConstraint = ColumnConstraintsBuilder.create().percentWidth(50).build(); grid.getColumnConstraints().addAll(halfConstraint, halfConstraint); stage.setScene(new Scene(grid, 300, 250)); stage.show(); }
/** * Creates a new {@link GridPane} containing the properties of the selected shortcut * * @return a new {@link GridPane} containing the properties of the selected shortcut */ private GridPane createPropertiesGrid() { final GridPane propertiesGrid = new GridPane(); propertiesGrid.getStyleClass().add("grid"); ColumnConstraints titleColumn = new ColumnConstraintsWithPercentage(30); ColumnConstraints valueColumn = new ColumnConstraintsWithPercentage(70); propertiesGrid.getColumnConstraints().addAll(titleColumn, valueColumn); // ensure that changes to the shortcutProperties map result in updates to the GridPane shortcutProperties.addListener((Observable invalidation) -> updateProperties(propertiesGrid)); // initialize the properties grid correctly updateProperties(propertiesGrid); return propertiesGrid; }
/** * Creates a new {@link GridPane} containing the properties of the selected shortcut * * @return a new {@link GridPane} containing the properties of the selected shortcut */ private GridPane createPropertiesGrid() { final GridPane propertiesGrid = new GridPane(); propertiesGrid.getStyleClass().add("grid"); ColumnConstraints titleColumn = new ColumnConstraintsWithPercentage(30); ColumnConstraints valueColumn = new ColumnConstraintsWithPercentage(70); propertiesGrid.getColumnConstraints().addAll(titleColumn, valueColumn); // ensure that changes to the shortcutProperties map result in updates to the GridPane shortcutProperties.addListener((Observable invalidation) -> updateProperties(propertiesGrid)); // initialize the properties grid correctly updateProperties(propertiesGrid); return propertiesGrid; }
@Override public void start( Stage stage ) { GridPane gp = new GridPane(); Label l = new Label( "before" ); Button b = new Button( "move" ); b.setOnAction( ( e ) -> { int i = GridPane.getColumnIndex( l ); System.out.println( "i = " + i ); l.setText( "after" ); GridPane.setColumnIndex( l, 2 ); } ); gp.add( l, 0, 0 ); gp.add( b, 1, 1 ); gp.setGridLinesVisible( true ); gp.getColumnConstraints().addAll( new ColumnConstraints( 70 ), new ColumnConstraints( 70 ), new ColumnConstraints( 70 ) ); final Scene scene = new Scene( gp, 400, 300 ); stage.setScene( scene ); stage.show(); }
public class Test extends Application { public void start(final Stage stage) throws Exception { final GridPane grid = new GridPane(); grid.getColumnConstraints().setAll( ColumnConstraintsBuilder.create().percentWidth(100/3.0).build(), ColumnConstraintsBuilder.create().percentWidth(100/3.0).build(), ColumnConstraintsBuilder.create().percentWidth(100/3.0).build() ); grid.add(new Button("One"),0,0); grid.add(new Button("Two"),1,0); grid.add(new Button("and three"),2,0); stage.setScene(new Scene(grid)); stage.show(); } public static void main(String[] args) { Application.launch(args); } }
private void setListEntry(ListCell<Label> listCell, Label label) { Image img = loadLableIcon(label); GridPane row = new GridPane(); row.setHgap(15); row.setVgap(15); ColumnConstraints col1 = new ColumnConstraints(); col1.setPercentWidth(90); ColumnConstraints col2 = new ColumnConstraints(); col2.setPercentWidth(10); ImageView icon = new ImageView(img); javafx.scene.control.Label name = new javafx.scene.control.Label(label.getName()); name.setMinWidth(120d); javafx.scene.control.Label amount = new javafx.scene.control.Label("" + label.getSize()); HBox iconAndName = new HBox(10); iconAndName.setAlignment(Pos.CENTER_LEFT); iconAndName.getChildren().addAll(icon, name); row.add(iconAndName, 0, 0); row.add(amount, 1, 0); row.getColumnConstraints().addAll(col1, col2); listCell.setGraphic(row); }
GridPane grid = new GridPane(); for (int rowIndex = 0; rowIndex < numRows; rowIndex++) { RowConstraints rc = new RowConstraints(); rc.setVgrow(Priority.ALWAYS) ; // allow row to grow rc.setFillHeight(true); // ask nodes to fill height for row // other settings as needed... grid.getRowConstraints().add(rc); } for (int colIndex = 0; colIndex < numColumns; rowIndex++) { ColumnConstraints cc = new ColumnConstraints(); cc.setHgrow(Priority.ALWAYS) ; // allow column to grow cc.setFillWidth(true); // ask nodes to fill space for column // other settings as needed... grid.getColumnConstraints().add(cc); }
public Pane toPane() { GridPane pane = new GridPane(); pane.setHgap(5); ColumnConstraints column0 = new ColumnConstraints(); ColumnConstraints column1 = new ColumnConstraints(); column1.setHgrow(Priority.ALWAYS); pane.getColumnConstraints().addAll(column0, column1); pane.add(label, 0, 0); pane.add(textField, 1, 0); pane.add(button, 2, 0); return pane; }
public void start(final Stage stage) throws Exception { final Button button0 = new Button("Start learning"); final Button button1 = new Button("Customize"); final GridPane cPane = new GridPane(); cPane.getChildren().addAll(button0, button1); GridPane.setConstraints(button0, 0, 0, 1, 1, HPos.CENTER, VPos.CENTER); GridPane.setConstraints(button1, 0, 1, 1, 1, HPos.CENTER, VPos.CENTER); final ColumnConstraints columnn0 = new ColumnConstraints(); columnn0.setPercentWidth(100); cPane.getColumnConstraints().addAll(columnn0); final RowConstraints row0 = new RowConstraints(1); row0.setPercentHeight(50); final RowConstraints row1 = new RowConstraints(1); row1.setPercentHeight(50); cPane.getRowConstraints().addAll(row0, row1); stage.setScene(new Scene(cPane)); stage.setWidth(200); stage.setHeight(100); stage.show(); }
/** * @return menu content containing input mappings (action -> key/mouse) */ protected final MenuContent createContentControls() { log.debug("createContentControls()"); GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(10, 10, 10, 10)); grid.getColumnConstraints().add(new ColumnConstraints(200, 200, 200, Priority.ALWAYS, HPos.LEFT, true)); grid.getRowConstraints().add(new RowConstraints(40, 40, 40, Priority.ALWAYS, VPos.CENTER, true)); // row 0 grid.setUserData(0); forEach(app.getInput().getBindings(), (action, trigger) -> addNewInputBinding(action, trigger, grid)); ScrollPane scroll = new FXGLScrollPane(grid); scroll.setVbarPolicy(ScrollBarPolicy.ALWAYS); scroll.setMaxHeight(app.getHeight() / 2.5); HBox hbox = new HBox(scroll); hbox.setAlignment(Pos.CENTER); return new MenuContent(hbox); }
@Override public void start( final Stage primaryStage ) { ColumnConstraints col1 = new ColumnConstraints(); col1.setHgrow( Priority.ALWAYS ); ColumnConstraints col2 = new ColumnConstraints(); col2.setHgrow( Priority.ALWAYS ); GridPane gridPane = new GridPane(); gridPane.setGridLinesVisible( true ); gridPane.getColumnConstraints().addAll( new ColumnConstraints( 60 ), col1, new ColumnConstraints( 100 ), col2 ); gridPane.addColumn( 0, new Button( "col 1" ) ); gridPane.addColumn( 1, new Button( "col 2" ) ); gridPane.addColumn( 2, new Button( "col 3" ) ); gridPane.addColumn( 3, new Button( "col 4" ) ); final Scene scene = new Scene( new VBox( gridPane ), 400, 300 ); primaryStage.setScene( scene ); primaryStage.show(); }
GridPane gridPane = new GridPane(); gridPane.setHgap(10); gridPane.setVgap(10); ColumnConstraints c1 = new ColumnConstraints(); c1.setHalignment(HPos.RIGHT); c1.setHgrow(Priority.NEVER); ColumnConstraints c2 = new ColumnConstraints(); c2.setHgrow(Priority.ALWAYS); c2.setFillWidth(true); ColumnConstraints c3 = new ColumnConstraints(); c3.setHalignment(HPos.RIGHT); c3.setHgrow(Priority.NEVER); ColumnConstraints c4 = new ColumnConstraints(); c4.setHgrow(Priority.ALWAYS); c4.setFillWidth(true); gridPane.getColumnConstraints().addAll(c1,c2,c3,c4);