Java Code Examples for javafx.scene.layout.Region#setPrefWidth()
The following examples show how to use
javafx.scene.layout.Region#setPrefWidth() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Builders.java From PDF4Teachers with Apache License 2.0 | 6 votes |
public static void setHBoxPosition(Region element, double width, double height, Insets margin){ if(width == -1){ HBox.setHgrow(element, Priority.ALWAYS); element.setMaxWidth(Double.MAX_VALUE); }else if(width != 0){ element.setPrefWidth(width); element.minWidthProperty().bind(new SimpleDoubleProperty(width)); } if(height == -1){ VBox.setVgrow(element, Priority.ALWAYS); }else if(height != 0){ element.setPrefHeight(height); element.minHeightProperty().bind(new SimpleDoubleProperty(height)); } HBox.setMargin(element, margin); }
Example 2
Source File: Builders.java From PDF4Teachers with Apache License 2.0 | 6 votes |
public static void setVBoxPosition(Region element, double width, double height, Insets margin){ if(width == -1){ HBox.setHgrow(element, Priority.ALWAYS); element.setMaxWidth(Double.MAX_VALUE); }else if(width != 0){ element.setPrefWidth(width); element.minWidthProperty().bind(new SimpleDoubleProperty(width)); } if(height == -1){ VBox.setVgrow(element, Priority.ALWAYS); }else if(height != 0){ element.setPrefHeight(height); element.minHeightProperty().bind(new SimpleDoubleProperty(height)); } VBox.setMargin(element, margin); }
Example 3
Source File: ClockOfClocks.java From medusademo with Apache License 2.0 | 6 votes |
@Override public void start(Stage stage) { Region spacer = new Region(); spacer.setPrefWidth(30); GridPane pane = new GridPane(); pane.add(hourLeft, 0, 0); pane.add(hourRight, 1, 0); pane.add(spacer, 2, 0); pane.add(minLeft, 3, 0); pane.add(minRight,4, 0); pane.setHgap(10); pane.setPadding(new Insets(20, 20, 25, 20)); Scene scene = new Scene(pane); stage.setTitle("Medusa Clock of Clocks"); stage.setScene(scene); stage.show(); timer.start(); // Calculate number of nodes calcNoOfNodes(pane); System.out.println(noOfNodes + " Nodes in SceneGraph"); }
Example 4
Source File: RadioButtonDrivenTextFieldsPane.java From pdfsam with GNU Affero General Public License v3.0 | 6 votes |
public void addRow(RadioButton radio, Region field, Text helpIcon) { requireNotNullArg(radio, "Cannot add a null radio"); requireNotNullArg(field, "Cannot add a null field"); GridPane.setValignment(radio, VPos.BOTTOM); GridPane.setValignment(field, VPos.BOTTOM); GridPane.setHalignment(radio, HPos.LEFT); GridPane.setHalignment(field, HPos.LEFT); GridPane.setFillWidth(field, true); field.setPrefWidth(300); field.setDisable(true); radio.selectedProperty().addListener((o, oldVal, newVal) -> { field.setDisable(!newVal); if (newVal) { field.requestFocus(); } }); radio.setToggleGroup(group); add(radio, 0, rows); add(field, 1, rows); if (nonNull(helpIcon)) { add(helpIcon, 2, rows); } rows++; }
Example 5
Source File: CellGestures.java From fxgraph with Do What The F*ck You Want To Public License | 5 votes |
private static void dragEast(MouseEvent event, Wrapper<Point2D> mouseLocation, Region region, double handleRadius) { final double deltaX = event.getSceneX() - mouseLocation.value.getX(); final double newMaxX = region.getLayoutX() + region.getWidth() + deltaX; if(newMaxX >= region.getLayoutX() && newMaxX <= region.getParent().getBoundsInLocal().getWidth() - handleRadius) { region.setPrefWidth(region.getPrefWidth() + deltaX); } }
Example 6
Source File: CellGestures.java From fxgraph with Do What The F*ck You Want To Public License | 5 votes |
private static void dragWest(MouseEvent event, Wrapper<Point2D> mouseLocation, Region region, double handleRadius) { final double deltaX = event.getSceneX() - mouseLocation.value.getX(); final double newX = region.getLayoutX() + deltaX; if(newX != 0 && newX <= region.getParent().getBoundsInLocal().getWidth() - handleRadius) { region.setLayoutX(newX); region.setPrefWidth(region.getPrefWidth() - deltaX); } }
Example 7
Source File: ToolbarHelper.java From phoebus with Eclipse Public License 1.0 | 5 votes |
/** @param width Desired width * @return 'Strut' that occupies requested width */ public static Node createStrut(int width) { final Region sep = new Region(); sep.setPrefWidth(width); sep.setMinWidth(Region.USE_PREF_SIZE); sep.setMaxWidth(Region.USE_PREF_SIZE); return sep; }
Example 8
Source File: TemplateField.java From pattypan with MIT License | 5 votes |
public VBox getRow() { Region spacer = new Region(); spacer.setMinWidth(20); VBox vb = new VBox(5); HBox hb = new HBox(10); HBox hbCheckbox = new HBox(10); valueText.setText(Settings.getSetting("var-" + name + "-value")); value = Settings.getSetting("var-" + name + "-value"); setSelection(Settings.getSetting("var-" + name + "-selection")); hb.getChildren().addAll(labelElement, buttonYes, buttonConst, buttonNo, spacer, valueText, new Region()); vb.getChildren().add(hb); if (name.equals("date")) { Region r = new Region(); r.setMaxWidth(622); r.setPrefWidth(622); r.setMinWidth(420); r.setMinHeight(30); CheckBox checkbox = new CheckBox(Util.text("choose-columns-exif")); checkbox.setMaxWidth(500); checkbox.setPrefWidth(500); checkbox.setMinWidth(305); checkbox.setSelected(Settings.getSetting("exifDate").equals("true")); checkbox.setOnAction((ActionEvent e) -> { Settings.setSetting("exifDate", checkbox.isSelected() ? "true" : ""); }); hbCheckbox.getChildren().addAll(r, checkbox); vb.getChildren().add(hbCheckbox); } return vb; }
Example 9
Source File: JFXUtil.java From jfxutils with Apache License 2.0 | 5 votes |
/** * Creates a "Scale Pane", which is a pane that scales as it resizes, instead of reflowing layout * like a normal pane. It can be used to create an effect like a presentation slide. There is no * attempt to preserve the aspect ratio. * <p> * If the region has an explicitly set preferred width and height, those are used unless * override is set true. * <p> * If the region already has a parent, the returned pane will replace it via the * {@link #replaceComponent(Node, Node)} method. The Region's parent must be a Pane in this case. * * @param region non-null Region * @param w default width, used if the region's width is calculated * @param h default height, used if the region's height is calculated * @param override if true, w,h is the region's "100%" size even if the region has an explicit * preferred width and height set. * * @return the created StackPane, with preferred width and height set based on size determined by * w, h, and override parameters. */ public static StackPane createScalePane( Region region, double w, double h, boolean override ) { //If the Region containing the GUI does not already have a preferred width and height, set it. //But, if it does, we can use that setting as the "standard" resolution. if ( override || region.getPrefWidth() == Region.USE_COMPUTED_SIZE ) region.setPrefWidth( w ); else w = region.getPrefWidth(); if ( override || region.getPrefHeight() == Region.USE_COMPUTED_SIZE ) region.setPrefHeight( h ); else h = region.getPrefHeight(); StackPane ret = new StackPane(); ret.setPrefWidth( w ); ret.setPrefHeight( h ); if ( region.getParent() != null ) replaceComponent( region, ret ); //Wrap the resizable content in a non-resizable container (Group) Group group = new Group( region ); //Place the Group in a StackPane, which will keep it centered ret.getChildren().add( group ); //Bind the scene's width and height to the scaling parameters on the group group.scaleXProperty().bind( ret.widthProperty().divide( w ) ); group.scaleYProperty().bind( ret.heightProperty().divide( h ) ); return ret; }
Example 10
Source File: NodeMenuItem.java From PDF4Teachers with Apache License 2.0 | 4 votes |
public void setFalseLeftData(){ Region spacer = new Region(); spacer.setPrefWidth(30); getNode().getChildren().set(0, spacer); }
Example 11
Source File: SearchBox.java From marathonv5 with Apache License 2.0 | 4 votes |
private void populateMenu(Map<DocumentType, List<SearchResult>> results) { contextMenu.getItems().clear(); for (Map.Entry<DocumentType, List<SearchResult>> entry : results.entrySet()) { boolean first = true; for(SearchResult result: entry.getValue()) { final SearchResult sr = result; final HBox hBox = new HBox(); hBox.setFillHeight(true); Label itemLabel = new Label(result.getName()); itemLabel.getStyleClass().add("item-label"); if (first) { first = false; Label groupLabel = new Label(result.getDocumentType().getPluralDisplayName()); groupLabel.getStyleClass().add("group-label"); groupLabel.setAlignment(Pos.CENTER_RIGHT); groupLabel.setMinWidth(USE_PREF_SIZE); groupLabel.setPrefWidth(70); hBox.getChildren().addAll(groupLabel,itemLabel); } else { Region spacer = new Region(); spacer.setMinWidth(USE_PREF_SIZE); spacer.setPrefWidth(70); hBox.getChildren().addAll(spacer,itemLabel); } // create a special node for hiding/showing popup content final Region popRegion = new Region(); popRegion.getStyleClass().add("search-menu-item-popup-region"); popRegion.setPrefSize(10, 10); hBox.getChildren().add(popRegion); final String name = (result.getDocumentType() == DocumentType.SAMPLE) ? result.getName() : result.getPackageName()+ ((result.getClassName() != null) ? "."+result.getClassName() : "") + ((result.getName() != null) ? "."+result.getName() : ""); final String shortDescription = (result.getShortDescription().length() == 160) ? result.getShortDescription() +"..." : result.getShortDescription(); popRegion.opacityProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { Platform.runLater( new Runnable() { // TODO runLater used here as a workaround for RT-14396 @Override public void run() { if (popRegion.getOpacity() == 1) { infoName.setText(name); infoDescription.setText(shortDescription); Point2D hBoxPos = hBox.localToScene(0, 0); extraInfoPopup.show(getScene().getWindow(), hBoxPos.getX() + contextMenu.getScene().getX() + contextMenu.getX() - infoBox.getPrefWidth() - 10, hBoxPos.getY() + contextMenu.getScene().getY() + contextMenu.getY() - 27 ); } } }); } }); // create menu item CustomMenuItem menuItem = new CustomMenuItem(hBox, true); menuItem.getStyleClass().add("search-menu-item"); contextMenu.getItems().add(menuItem); // handle item selection menuItem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { ///System.out.println("SearchBox.handle menuItem.setOnAction"); Ensemble2.getEnsemble2().goToPage(sr.getEnsemblePath(),true); } }); } } }
Example 12
Source File: ButtonBarX.java From marathonv5 with Apache License 2.0 | 4 votes |
private void sizeButton(Node btn, double pref) { if (btn instanceof Region) { Region regionBtn = (Region) btn; regionBtn.setPrefWidth(pref); } }
Example 13
Source File: SearchBox.java From marathonv5 with Apache License 2.0 | 4 votes |
private void populateMenu(Map<DocumentType, List<SearchResult>> results) { contextMenu.getItems().clear(); for (Map.Entry<DocumentType, List<SearchResult>> entry : results.entrySet()) { boolean first = true; for(SearchResult result: entry.getValue()) { final SearchResult sr = result; final HBox hBox = new HBox(); hBox.setFillHeight(true); Label itemLabel = new Label(result.getName()); itemLabel.getStyleClass().add("item-label"); if (first) { first = false; Label groupLabel = new Label(result.getDocumentType().getPluralDisplayName()); groupLabel.getStyleClass().add("group-label"); groupLabel.setAlignment(Pos.CENTER_RIGHT); groupLabel.setMinWidth(USE_PREF_SIZE); groupLabel.setPrefWidth(70); hBox.getChildren().addAll(groupLabel,itemLabel); } else { Region spacer = new Region(); spacer.setMinWidth(USE_PREF_SIZE); spacer.setPrefWidth(70); hBox.getChildren().addAll(spacer,itemLabel); } // create a special node for hiding/showing popup content final Region popRegion = new Region(); popRegion.getStyleClass().add("search-menu-item-popup-region"); popRegion.setPrefSize(10, 10); hBox.getChildren().add(popRegion); final String name = (result.getDocumentType() == DocumentType.SAMPLE) ? result.getName() : result.getPackageName()+ ((result.getClassName() != null) ? "."+result.getClassName() : "") + ((result.getName() != null) ? "."+result.getName() : ""); final String shortDescription = (result.getShortDescription().length() == 160) ? result.getShortDescription() +"..." : result.getShortDescription(); popRegion.opacityProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { Platform.runLater( new Runnable() { // TODO runLater used here as a workaround for RT-14396 @Override public void run() { if (popRegion.getOpacity() == 1) { infoName.setText(name); infoDescription.setText(shortDescription); Point2D hBoxPos = hBox.localToScene(0, 0); extraInfoPopup.show(getScene().getWindow(), hBoxPos.getX() + contextMenu.getScene().getX() + contextMenu.getX() - infoBox.getPrefWidth() - 10, hBoxPos.getY() + contextMenu.getScene().getY() + contextMenu.getY() - 27 ); } } }); } }); // create menu item CustomMenuItem menuItem = new CustomMenuItem(hBox, true); menuItem.getStyleClass().add("search-menu-item"); contextMenu.getItems().add(menuItem); // handle item selection menuItem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { ///System.out.println("SearchBox.handle menuItem.setOnAction"); Ensemble2.getEnsemble2().goToPage(sr.getEnsemblePath(),true); } }); } } }
Example 14
Source File: SettingNumberField.java From MSPaintIDE with MIT License | 4 votes |
private Node getHSpacer(double width) { Region spacer = new Region(); spacer.setPrefWidth(width); HBox.setHgrow(spacer, Priority.NEVER); return spacer; }
Example 15
Source File: SettingsFilePicker.java From MSPaintIDE with MIT License | 4 votes |
private Node getHSpacer(double width) { Region spacer = new Region(); spacer.setPrefWidth(width); HBox.setHgrow(spacer, Priority.NEVER); return spacer; }