Java Code Examples for javafx.scene.layout.Pane#setPrefSize()
The following examples show how to use
javafx.scene.layout.Pane#setPrefSize() .
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: AnimationApp.java From FXTutorials with MIT License | 6 votes |
private Parent createContent() { Pane root = new Pane(); root.setPrefSize(800, 600); NotificationPane pane = new NotificationPane(200, 600); pane.setTranslateX(800 - 200); Button btn = new Button("Animate"); btn.setOnAction(e -> { pane.animate(); }); root.getChildren().addAll(btn, pane); return root; }
Example 2
Source File: L4dFX.java From FXTutorials with MIT License | 6 votes |
private Parent createContent() { Pane root = new Pane(); root.setPrefSize(240 * 3, 240 * 3); Canvas canvas = new Canvas(240 * 3, 240 * 3); g = canvas.getGraphicsContext2D(); g.scale(3, 3); // AnimationTimer timer = new AnimationTimer() { // @Override // public void handle(long now) { // t += 0.017; // //draw(); // } // }; // timer.start(); new Thread(this::run).start(); root.getChildren().add(canvas); return root; }
Example 3
Source File: Slide.java From ShootOFF with GNU General Public License v3.0 | 6 votes |
public void showControls() { // If we have less than the maximum number of control buttons // add empty panes as place holders for missing buttons to // ensure control button alignment and size is maintained. if (controlNodes.size() < MAX_CONTROL_BUTTONS) { final int sizeDelta = MAX_CONTROL_BUTTONS - controlNodes.size(); for (int i = 0; i < sizeDelta; i++) { final Pane placeHolderPane = new Pane(); placeHolderPane.setPrefSize(CONTROL_BUTTON_WIDTH, CONTROL_BUTTON_HEIGHT); controlNodes.add(placeHolderPane); } } show(parentControls, controlNodes, savedControls); }
Example 4
Source File: Client.java From SynchronizeFX with GNU Lesser General Public License v3.0 | 6 votes |
private void addNote(final Note note) { final Pane newNote = new Pane(); final Position2D position = note.getPosition(); newNote.getChildren().add(new Label(note.getText())); newNote.styleProperty().set("-fx-background-color: red;"); newNote.setPrefSize(NOTE_WIDTH, NOTE_HEIGHT); newNote.layoutXProperty().bind(position.xProperty().multiply(root.widthProperty())); newNote.layoutYProperty().bind(position.yProperty().multiply(root.heightProperty())); newNote.setOnMouseDragged(new EventHandler<MouseEvent>() { @Override public void handle(final MouseEvent event) { position.setX(event.getSceneX() / root.getWidth()); position.setY(event.getSceneY() / root.getHeight()); event.consume(); } }); root.getChildren().add(newNote); notes.put(note, newNote); }
Example 5
Source File: SceneManager.java From Schillsaver with MIT License | 6 votes |
/** Swaps the current and previous scenes, so that the previous scene is displayed. */ public void swapToPreviousScene() { final Controller tempC = previousController; previousController = currentController; currentController = tempC; final Scene tempS = previousScene; previousScene = currentScene; currentScene = tempS; // Set new scene's pane to be the same size as the previous pane's scene. final Pane previousPane = previousController.getView().getPane(); final Pane currentPane = currentController.getView().getPane(); currentPane.setPrefSize(previousPane.getWidth(), previousPane.getHeight()); stage.setScene(currentScene); }
Example 6
Source File: TriangleCell.java From fxgraph with Do What The F*ck You Want To Public License | 6 votes |
@Override public Region getGraphic(Graph graph) { final double width = 50; final double height = 50; final Polygon view = new Polygon(width / 2, 0, width, height, 0, height); view.setStroke(Color.RED); view.setFill(Color.RED); final Pane pane = new Pane(view); pane.setPrefSize(50, 50); final Scale scale = new Scale(1, 1); view.getTransforms().add(scale); scale.xProperty().bind(pane.widthProperty().divide(50)); scale.yProperty().bind(pane.heightProperty().divide(50)); CellGestures.makeResizable(pane); return pane; }
Example 7
Source File: IOSApp.java From FXTutorials with MIT License | 6 votes |
private Parent createContent() { Pane root = new Pane(); root.setPrefSize(300, 300); Rectangle bg = new Rectangle(300, 300); ToggleSwitch toggle = new ToggleSwitch(); toggle.setTranslateX(100); toggle.setTranslateY(100); Text text = new Text(); text.setFont(Font.font(18)); text.setFill(Color.WHITE); text.setTranslateX(100); text.setTranslateY(200); text.textProperty().bind(Bindings.when(toggle.switchedOnProperty()).then("ON").otherwise("OFF")); root.getChildren().addAll(toggle, text); return root; }
Example 8
Source File: AsteroidsApp.java From FXTutorials with MIT License | 6 votes |
private Parent createContent() { root = new Pane(); root.setPrefSize(600, 600); player = new Player(); player.setVelocity(new Point2D(1, 0)); addGameObject(player, 300, 300); AnimationTimer timer = new AnimationTimer() { @Override public void handle(long now) { onUpdate(); } }; timer.start(); return root; }
Example 9
Source File: RectangleCell.java From fxgraph with Do What The F*ck You Want To Public License | 5 votes |
@Override public Region getGraphic(Graph graph) { final Rectangle view = new Rectangle(50, 50); view.setStroke(Color.DODGERBLUE); view.setFill(Color.DODGERBLUE); final Pane pane = new Pane(view); pane.setPrefSize(50, 50); view.widthProperty().bind(pane.prefWidthProperty()); view.heightProperty().bind(pane.prefHeightProperty()); CellGestures.makeResizable(pane); return pane; }
Example 10
Source File: NotificationPanel.java From trex-stateless-gui with Apache License 2.0 | 5 votes |
/** * Build component UI */ private void buildUI() { this.setSpacing(5); // add notification message notificationContainer = new Pane(); notificationContainer.setPrefSize(184, 64); notificationContainer.getStyleClass().add("notificationContainer"); notificationLabel = new Label(); notificationLabel.setPrefSize(155, 60); notificationLabel.setWrapText(true); notificationLabel.getStyleClass().add("notificationMsg"); notificationContainer.getChildren().add(notificationLabel); getChildren().add(notificationContainer); // add notification icon VBox iconHolder = new VBox(); iconHolder.setPrefHeight(68); iconHolder.setAlignment(Pos.CENTER); ImageView notificationIcon = new ImageView(new Image("/icons/info_icon.png")); notificationIcon.getStyleClass().add("notificationIcon"); notificationIcon.setOnMouseClicked((MouseEvent event) -> { notificationContainer.setVisible(!notificationContainer.isVisible()); }); iconHolder.getChildren().add(notificationIcon); getChildren().add(iconHolder); }
Example 11
Source File: Main.java From FXTutorials with MIT License | 5 votes |
private Parent createContent() { Pane root = new Pane(); root.setPrefSize(1280, 720); menu.setTranslateX(600); menu.setTranslateY(300); menu.setScaleX(2); menu.setScaleY(2); menu.selectedItem.addListener((obs, old, newValue) -> { System.out.println("Selected: " + newValue); }); try (InputStream is = getClass().getResourceAsStream("farcry_gameplay.jpg")) { Image img = new Image(is); ImageView imgView = new ImageView(img); imgView.setFitWidth(1280); imgView.setFitHeight(720); root.getChildren().add(imgView); } catch (Exception e) { System.out.println("Failed to load image: " + e.getMessage()); } root.getChildren().addAll(menu); return root; }
Example 12
Source File: FridayFunSkin.java From WorkbenchFX with Apache License 2.0 | 5 votes |
@Override public void initializeParts() { double center = ARTBOARD_SIZE * 0.5; int width = 15; double radius = center - width; backgroundCircle = new Circle(center, center, radius); backgroundCircle.getStyleClass().add("backgroundCircle"); bar = new Arc(center, center, radius, radius, 90.0, 0.0); bar.getStyleClass().add("bar"); bar.setType(ArcType.OPEN); thumb = new Circle(center, center + center - width, 13); thumb.getStyleClass().add("thumb"); valueDisplay = createCenteredText(center, center, "valueDisplay"); ticks = createTicks(center, center, 60, 360.0, 6, 33, 0, "tick"); tickLabels = new ArrayList<>(); int labelCount = 8; for (int i = 0; i < labelCount; i++) { double r = 95; double nextAngle = i * 360.0 / labelCount; Point2D p = pointOnCircle(center, center, r, nextAngle); Text tickLabel = createCenteredText(p.getX(), p.getY(), "tickLabel"); tickLabels.add(tickLabel); } updateTickLabels(); drawingPane = new Pane(); drawingPane.getStyleClass().add("numberRange"); drawingPane.setMaxSize(ARTBOARD_SIZE, ARTBOARD_SIZE); drawingPane.setMinSize(ARTBOARD_SIZE, ARTBOARD_SIZE); drawingPane.setPrefSize(ARTBOARD_SIZE, ARTBOARD_SIZE); }
Example 13
Source File: Main.java From FXTutorials with MIT License | 5 votes |
private Parent createContent() { Pane root = new Pane(); root.setPrefSize(800, 600); progress.setTranslateX(700); progress.setTranslateY(500); resourceLoader.valueProperty().addListener((obs, old, newValue) -> { root.getChildren().add(newValue); }); root.getChildren().add(progress); return root; }
Example 14
Source File: Main.java From FXTutorials with MIT License | 5 votes |
private Parent createContent() { Pane root = new Pane(); root.setPrefSize(800, 600); Dice dice1 = new Dice(); Dice dice2 = new Dice(); dice1.setTranslateX(100); dice1.setTranslateY(200); dice2.setTranslateX(300); dice2.setTranslateY(200); Button btn = new Button("New target"); btn.setOnAction(event -> { target.set((int)(Math.random() * (Dice.MAX_VALUE * 2 + 1))); }); btn.setTranslateX(400); btn.setTranslateY(200); SimpleBooleanProperty bool = new SimpleBooleanProperty(); bool.bind(target.isEqualTo(dice1.valueProperty.add(dice2.valueProperty))); Text message = new Text(); message.textProperty().bind(target.asString().concat(bool.asString())); message.setTranslateX(500); message.setTranslateY(200); root.getChildren().addAll(dice1, dice2, btn, message); return root; }
Example 15
Source File: PaneEllipsesDemo.java From phoebus with Eclipse Public License 1.0 | 4 votes |
@Override public void start(final Stage stage) { Color [] value_colors = getColors(170); //10101010 String[] labels = {"1","2","4","8","16","32","64","128"}; //===widget-relevant code===// Pane pane = new Pane(); Ellipse ellipses [] = new Ellipse [number]; Text textLabels [] = new Text [number]; for (int i = 0; i < number; i++) { ellipses[i] = new Ellipse(); textLabels[i] = createText(labels[i]); pane.getChildren().addAll(ellipses[i], textLabels[i]); } pane.setPrefSize(size*number, size); for (int i = 0; i < number; i++) { ellipses[i].setCenterX(size/2 + i*size); ellipses[i].setCenterY(size/2); ellipses[i].setRadiusX(size/2); ellipses[i].setRadiusY(size/2); textLabels[i].setX(i*size); textLabels[i].setY(size/2); textLabels[i].setWrappingWidth(size); } for (int i = 0; i < number; i++) ellipses[i].setFill( new LinearGradient(0, 0, 0.5, 0.5, true, CycleMethod.NO_CYCLE, new Stop(0, value_colors[i].interpolate(Color.WHITESMOKE, 0.8)), new Stop(1, value_colors[i]))); //=end widget-relevant code=// //VBox.setVgrow(pane, Priority.NEVER); VBox vbox = new VBox(pane); final Scene scene = new Scene(vbox, 800, 700); stage.setScene(scene); stage.setTitle("Pane with Ellipses"); stage.show(); }
Example 16
Source File: ColorRegulator.java From regulators with Apache License 2.0 | 4 votes |
private void initGraphics() { dropShadow = new DropShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), PREFERRED_WIDTH * 0.016, 0.0, 0, PREFERRED_WIDTH * 0.028); highlight = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(255, 255, 255, 0.2), PREFERRED_WIDTH * 0.008, 0.0, 0, PREFERRED_WIDTH * 0.008); innerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.2), PREFERRED_WIDTH * 0.008, 0.0, 0, -PREFERRED_WIDTH * 0.008); highlight.setInput(innerShadow); dropShadow.setInput(highlight); Stop[] stops = { new Stop(0.0, Color.rgb(255,255,0)), new Stop(0.125, Color.rgb(255,0,0)), new Stop(0.375, Color.rgb(255,0,255)), new Stop(0.5, Color.rgb(0,0,255)), new Stop(0.625, Color.rgb(0,255,255)), new Stop(0.875, Color.rgb(0,255,0)), new Stop(1.0, Color.rgb(255,255,0)) }; List<Stop> reorderedStops = reorderStops(stops); gradientLookup = new GradientLookup(stops); barGradient = new ConicalGradient(reorderedStops); barArc = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.46, PREFERRED_HEIGHT * 0.46, BAR_START_ANGLE, 0); barArc.setType(ArcType.OPEN); barArc.setStrokeLineCap(StrokeLineCap.ROUND); barArc.setFill(null); barArc.setStroke(barGradient.getImagePattern(new Rectangle(0, 0, PREFERRED_WIDTH, PREFERRED_HEIGHT))); buttonOn = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.46, PREFERRED_HEIGHT * 0.46, -125, 34.75); buttonOn.setFill(null); buttonOn.setStroke(color.get()); buttonOn.setStrokeLineCap(StrokeLineCap.BUTT); buttonOn.setStrokeWidth(PREFERRED_WIDTH * 0.072); buttonOn.setEffect(dropShadow); buttonOff = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.46, PREFERRED_HEIGHT * 0.46, -89.75, 34.75); buttonOff.setFill(null); buttonOff.setStroke(color.get()); buttonOff.setStrokeLineCap(StrokeLineCap.BUTT); buttonOff.setStrokeWidth(PREFERRED_WIDTH * 0.072); buttonOff.setEffect(dropShadow); double center = PREFERRED_WIDTH * 0.5; ring = Shape.subtract(new Circle(center, center, PREFERRED_WIDTH * 0.42), new Circle(center, center, PREFERRED_WIDTH * 0.3)); ring.setFill(color.get()); ring.setEffect(highlight); mainCircle = new Circle(); mainCircle.setFill(color.get().darker().darker()); textOn = new Text("ON"); textOn.setFill(textColor.get()); textOn.setTextOrigin(VPos.CENTER); textOn.setMouseTransparent(true); textOn.setRotate(17); textOff = new Text("OFF"); textOff.setFill(textColor.get()); textOff.setTextOrigin(VPos.CENTER); textOff.setMouseTransparent(true); textOff.setRotate(-17); indicatorRotate = new Rotate(-ANGLE_RANGE * 0.5, center, center); indicatorGlow = new DropShadow(BlurType.TWO_PASS_BOX, getIndicatorColor(), PREFERRED_WIDTH * 0.02, 0.0, 0, 0); indicatorInnerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.5), PREFERRED_WIDTH * 0.008, 0.0, 0, PREFERRED_WIDTH * 0.008); indicatorHighlight = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(255, 255, 255, 0.35), PREFERRED_WIDTH * 0.008, 0.0, 0, -PREFERRED_WIDTH * 0.008); indicatorHighlight.setInput(indicatorInnerShadow); indicator = new Circle(); indicator.setFill(color.get().darker()); indicator.setStroke(color.get().darker().darker()); indicator.setMouseTransparent(true); indicator.getTransforms().add(indicatorRotate); Group indicatorGroup = new Group(indicator); indicatorGroup.setEffect(indicatorHighlight); innerRing = Shape.subtract(new Circle(center, center, PREFERRED_WIDTH * 0.24), new Circle(center, center, PREFERRED_WIDTH * 0.2)); innerRing.setFill(color.get()); currentColorCircle = new Circle(); currentColorCircle.setFill(targetColor.get()); currentColorCircle.setVisible(isOn()); pane = new Pane(barArc, ring, mainCircle, currentColorCircle, innerRing, indicatorGroup, buttonOn, textOn, buttonOff, textOff); pane.setPrefSize(PREFERRED_HEIGHT, PREFERRED_HEIGHT); pane.setBackground(new Background(new BackgroundFill(color.get().darker(), new CornerRadii(1024), Insets.EMPTY))); pane.setEffect(highlight); getChildren().setAll(pane); }
Example 17
Source File: Story.java From mars-sim with GNU General Public License v3.0 | 4 votes |
/** render the application on a stage */ public StackPane createGUI() { SwingUtilities.invokeLater(() -> { //Simulation.instance().getJConsole().write(ADDRESS,Color.ORANGE,Color.BLACK); }); // place the address content in a bordered title pane. Pane titledContent = new BorderedTitledPane(TITLE, getContent()); titledContent.getStyleClass().add("titled-address"); titledContent.setPrefSize(800, 745); // make some crumpled paper as a background. final Image paper = new Image(PAPER); final ImageView paperView = new ImageView(paper); ColorAdjust colorAdjust = new ColorAdjust(0, -.2, .2, 0); paperView.setEffect(colorAdjust); // place the address content over the top of the paper. StackPane stackedContent = new StackPane(); stackedContent.getChildren().addAll(paperView, titledContent); // manage the viewport of the paper background, to size it to the content. paperView.setViewport(new Rectangle2D(0, 0, titledContent.getPrefWidth(), titledContent.getPrefHeight())); stackedContent.layoutBoundsProperty().addListener(new ChangeListener<Bounds>() { @Override public void changed(ObservableValue<? extends Bounds> observableValue, Bounds oldValue, Bounds newValue) { paperView.setViewport(new Rectangle2D( newValue.getMinX(), newValue.getMinY(), Math.min(newValue.getWidth(), paper.getWidth()), Math.min(newValue.getHeight(), paper.getHeight()) )); } }); // blend the content into the paper and make it look old. titledContent.setMaxWidth(paper.getWidth()); titledContent.setEffect(new SepiaTone()); titledContent.setBlendMode(BlendMode.MULTIPLY); // configure and display the scene and stage. //Scene scene = new Scene(stackedContent); //scene.getStylesheets().add(getClass().getResource("/css/gettysburg.css").toExternalForm()); /* stage.setTitle(TITLE); stage.getIcons().add(new Image(ICON)); stage.setScene(scene); stage.setMinWidth(600); stage.setMinHeight(500); stage.show(); */ // make the scrollbar in the address scroll pane hide when it is not needed. makeScrollFadeable(titledContent.lookup(".address > .scroll-pane")); return stackedContent; }
Example 18
Source File: LabelTest.java From oim-fx with MIT License | 4 votes |
@Override public void start(Stage primaryStage) { try { Group root = new Group(); Scene scene = new Scene(root, 400, 400); Pane p = new Pane(); p.setPrefSize(400, 400); p.setBackground(new Background(new BackgroundFill(Color.GOLD, null, null))); root.getChildren().add(p); primaryStage.setScene(scene); primaryStage.setTitle("Conversation about Bubbles with Elltz"); primaryStage.show(); Label bl1 = new Label(); bl1.relocate(10, 50); bl1.setText("Hi Elltz -:)"); bl1.setBackground(new Background(new BackgroundFill(Color.YELLOWGREEN, null, null))); Label bl2 = new Label(); bl2.relocate(310, 100); bl2.setText("Heloooo Me"); bl2.setBackground(new Background(new BackgroundFill(Color.GREENYELLOW, null, null))); Label bl3 = new Label(); bl3.relocate(10, 150); bl3.setText("you know this would be a nice library"); bl3.setBackground(new Background(new BackgroundFill(Color.YELLOWGREEN, null, null))); Label bl4 = new Label(); bl4.relocate(165, 200); bl4.setText("uhmm yea, kinda, but yknow,im tryna \nact like im not impressed"); bl4.setBackground(new Background(new BackgroundFill(Color.GREENYELLOW, null, null))); Label bl5 = new Label(); bl5.relocate(10, 250); bl5.setText("yea! yea! i see that, lowkey.. you not gonna\n get upvotes though..lmao"); bl5.setBackground(new Background(new BackgroundFill(Color.YELLOWGREEN, null, null))); Label bl6 = new Label(); bl6.relocate(165, 300); bl6.setText("Man! shut up!!.. what you know about\n upvotes."); bl6.setBackground(new Background(new BackgroundFill(Color.GREENYELLOW, null, null))); p.getChildren().addAll(bl1, bl2, bl3, bl4, bl5, bl6); } catch (Exception e) { e.printStackTrace(); } }
Example 19
Source File: TetrisApp.java From FXTutorials with MIT License | 4 votes |
private Parent createContent() { Pane root = new Pane(); root.setPrefSize(GRID_WIDTH * TILE_SIZE, GRID_HEIGHT * TILE_SIZE); Canvas canvas = new Canvas(GRID_WIDTH * TILE_SIZE, GRID_HEIGHT * TILE_SIZE); g = canvas.getGraphicsContext2D(); root.getChildren().addAll(canvas); // original.add(new Tetromino(Color.BLUE, // new Piece(0, Direction.DOWN), // new Piece(1, Direction.LEFT), // new Piece(1, Direction.RIGHT), // new Piece(2, Direction.RIGHT) // )); // original.add(new Tetromino(Color.RED, // new Piece(0, Direction.DOWN), // new Piece(1, Direction.LEFT), // new Piece(1, Direction.RIGHT), // new Piece(1, Direction.DOWN) // )); // original.add(new Tetromino(Color.GREEN, new Piece(0, Direction.DOWN), new Piece(1, Direction.RIGHT), new Piece(2, Direction.RIGHT), new Piece(1, Direction.DOWN))); original.add(new Tetromino(Color.GRAY, new Piece(0, Direction.DOWN), new Piece(1, Direction.RIGHT), new Piece(1, Direction.RIGHT, Direction.DOWN), new Piece(1, Direction.DOWN))); spawn(); AnimationTimer timer = new AnimationTimer() { @Override public void handle(long now) { time += 0.017; if (time >= 0.5) { update(); render(); time = 0; } } }; timer.start(); return root; }
Example 20
Source File: Main.java From FXTutorials with MIT License | 4 votes |
@Override public void start(Stage primaryStage) throws Exception { target.setFill(Color.RED); target.setOnMouseClicked(event -> { score += 100; screenText.setText("Score: " + score); }); screenText.setTranslateX(500); screenText.setTranslateY(50); gunInfo.setTranslateX(500); gunInfo.setTranslateY(100); Pane root = new Pane(); root.setPrefSize(600, 600); root.getChildren().addAll(target, screenText, gunInfo); Scene scene = new Scene(root); scene.setOnMouseClicked(event -> { if (event.getButton() == MouseButton.PRIMARY) { gun.fire(); } else { gun.reload(); } gunInfo.setText("Bullets: " + gun.getClip().getBullets()); }); Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> { Platform.runLater(() -> { target.setTranslateX(Math.random() * 560); target.setTranslateY(Math.random() * 560); }); }, 0, 1, TimeUnit.SECONDS); primaryStage.setOnCloseRequest(event -> System.exit(0)); primaryStage.setScene(scene); primaryStage.show(); }