@Override public void start(Stage stage) { Pane root = new Pane(); for(int i = 0 ;i < 4000; i++) { Label child = new Label("label" + i); child.setLayoutX(Math.random() * 500 + 100); child.setLayoutY(Math.random() * 500+ 100); root.getChildren().add(child); } root.getChildren().add(build()); FPSDecorator decorator = new FPSDecorator(stage, root); final Scene scene = new Scene(decorator, 800, 800); stage.setScene(scene); stage.setResizable(true); stage.show(); afterShow(stage); }
colorBox = new Pane(); colorBox.getStyleClass().add("color-box"); colorBox.setManaged(false); colorBox.backgroundProperty() .get() != null ? colorBox.getBackground() .getFills() .get(0) .getRadii() : new CornerRadii( 3), colorBox.backgroundProperty() .get() != null ? colorBox.getBackground() .getFills() .get(0) .getInsets() : Insets.EMPTY)); }, colorBox.backgroundProperty())); colorBox.setClip(pickerColorClip); colorBox.getChildren().add(displayNode); updateColor(); final JFXRippler rippler = new JFXRippler(colorBox, JFXRippler.RipplerMask.FIT);
private void updateColor() { final ColorPicker colorPicker = (ColorPicker) getSkinnable(); Color color = colorPicker.getValue(); // update picker box color Color circleColor = color == null ? Color.WHITE : color; Circle colorCircle = new Circle(); colorCircle.setFill(circleColor); colorCircle.setLayoutX(colorBox.getWidth() / 4); colorCircle.setLayoutY(colorBox.getHeight() / 2); colorBox.getChildren().add(colorCircle); Timeline animateColor = new Timeline(new KeyFrame(Duration.millis(240), new KeyValue(colorCircle.radiusProperty(), 200, Interpolator.EASE_BOTH))); animateColor.setOnFinished((finish) -> { JFXNodeUtils.updateBackground(colorBox.getBackground(), colorBox, colorCircle.getFill()); colorBox.getChildren().remove(colorCircle); }); animateColor.play(); // update label color displayNode.setTextFill(circleColor.grayscale().getRed() < 0.5 ? Color.valueOf( "rgba(255, 255, 255, 0.87)") : Color.valueOf("rgba(0, 0, 0, 0.87)")); if (colorLabelVisible.get()) { displayNode.setText(JFXNodeUtils.colorToHex(circleColor)); } else { displayNode.setText(""); } }
/*************************************************************************** * * Public API * * **************************************************************************/ public void registerSnackbarContainer(Pane snackbarContainer) { if (snackbarContainer != null) { if (this.snackbarContainer != null) { //since listeners are added the container should be properly registered/unregistered throw new IllegalArgumentException("Snackbar Container already set"); } this.snackbarContainer = snackbarContainer; this.snackbarContainer.getChildren().add(this); this.snackbarContainer.heightProperty().addListener(weakSizeListener); this.snackbarContainer.widthProperty().addListener(weakSizeListener); } }
protected final void createRippleUI() { // create rippler panels rippler = new RippleGenerator(); ripplerPane = new StackPane(); ripplerPane.setMouseTransparent(true); ripplerPane.getChildren().add(rippler); getChildren().add(ripplerPane); }
stage.setTitle("BPM"); BorderPane mainPanel = new BorderPane(); VBox nameList = new VBox(); nameList.getChildren().add(new Label("Data")); nameList.setPrefWidth(150); Pane canvas = new Pane(); canvas.setStyle("-fx-background-color: #ffe3c3;"); canvas.setPrefSize(400,300); Circle anchor = new Circle(10); Rectangle rect = new Rectangle(50,50); rect.setX(100); rect.setY(100); canvas.getChildren().addAll(rect, anchor); Rectangle bound = new Rectangle(400,300); canvas.setClip(bound); rect.setOnMouseDragged(event -> {
@Override public void start(Stage primaryStage) { Pane mainPane = new Pane(); Rectangle rect = new Rectangle(0, 0, 30, 30); rect.setFill(Color.RED); mainPane.getChildren().add(rect); Scene scene = new Scene(mainPane, 500, 500); primaryStage.setScene(scene); primaryStage.show(); rect.setOnDragDetected(event -> { Node on = (Node)event.getSource(); Dragboard db = on.startDragAndDrop(TransferMode.ANY); db.setContent(makeClipboardContent(event, on, null)); event.consume(); }); mainPane.setOnDragOver(e->{ e.acceptTransferModes(TransferMode.ANY); }); mainPane.setOnDragExited(e->{ rect.setLayoutX(e.getSceneX()-rect.getWidth()/2d); rect.setLayoutY(e.getSceneY()-rect.getHeight()/2d); }); }
Pane rootPane = new StackPane(); Scene mainScene = new Scene(rootPane); Button btn = new Button("alert"); rootPane.getChildren().add(btn); Rectangle blockingRect = new Rectangle(); blockingRect.widthProperty().bind(primaryStage.widthProperty()); blockingRect.heightProperty().bind(primaryStage.heightProperty()); blockingRect.setFill(Color.LIGHTBLUE); blockingRect.setOpacity(0.5); btn.setOnAction(event -> { rootPane.getChildren().addAll(blockingRect, alertPane); }); alertOKButton.setOnAction(event -> { rootPane.getChildren().removeAll(blockingRect, alertPane); }); primaryStage.setFullScreen(true); primaryStage.setScene(mainScene); primaryStage.show();
Label label = new Label(); Pane paneA = new Pane(); Pane paneB = new Pane(); Rectangle objectA = new Rectangle(50, 30); objectA.setFill(Paint.valueOf("red")); objectA.setX(100); objectA.setY(100); objectA.setRotate(10); objectB.setY(60); paneB.getChildren().add(objectB); paneA.getChildren().addAll(objectA, paneB); Bounds objA = objectA.localToScene(objectA.getBoundsInLocal()); label.setText("ObjectA intersects ObjectB"); } else { label.setText("ObjectA does not intersect ObjectB"); root.setBottom(label); Scene scene = new Scene(root, 300, 250); primaryStage.setTitle("Collision Detection"); primaryStage.setScene(scene); primaryStage.show();
public void start(Stage primaryStage) { final Label txt = new Label("Example"); txt.relocate(100, 100); Pane root = new Pane(); final Rectangle border = new Rectangle(); border.setFill(Color.TRANSPARENT); border.setStroke(Color.RED); txt.boundsInParentProperty().addListener(new ChangeListener<Bounds>() { root.getChildren().addAll(txt, border); root.setOnMouseClicked(new EventHandler<MouseEvent>() { Scene scene = new Scene(root, 300, 250); primaryStage.setTitle("Hello World!"); primaryStage.setScene(scene); primaryStage.show();
public class ClipPane extends Application { @Override public void start(Stage stage) throws Exception { Pane clipPane = new Pane(); clipPane.setStyle("-fx-border-color: red;"); clipPane.setPrefSize(200, 200); Rectangle rect = new Rectangle(200, 200); clipPane.setClip(rect); Button btn = new Button("Hello, world!"); btn.relocate(120, 0); clipPane.getChildren().add(btn); AnchorPane root = new AnchorPane(); root.getChildren().add(clipPane); AnchorPane.setTopAnchor(clipPane, 50.); AnchorPane.setLeftAnchor(clipPane, 50.); stage.setScene(new Scene(root, 300, 300)); stage.show(); } public static void main(String[] args) { launch(); } }
final Rectangle rect1 = new Rectangle(10, 70, 50, 50); final Rectangle rect2 = new Rectangle(10, 150, 50, 50); Button btn = new Button("Play"); btn.setOnAction(new EventHandler<ActionEvent>() { rect1.setVisible(false); Pane root = new Pane(); root.getChildren().addAll(rect1, rect2, btn); primaryStage.setScene(scene); primaryStage.show();
stage.initStyle(StageStyle.TRANSPARENT); stage.setScene(scene); stage.show(); Pane shadowPane = new Pane(); shadowPane.setStyle( "-fx-background-color: white;" + "-fx-effect: dropshadow(gaussian, red, " + shadowSize + ", 0, 0, 0);" + ); Rectangle innerRect = new Rectangle(); Rectangle outerRect = new Rectangle(); shadowPane.layoutBoundsProperty().addListener( (observable, oldBounds, newBounds) -> { innerRect.relocate( newBounds.getMinX() + shadowSize, newBounds.getMinY() + shadowSize shadowPane.setClip(clip);
public void start(Stage stage) throws Exception { Pane root = new Pane(); int grid_x = 7; //number of rows int grid_y = 7; //number of columns for (int x = 0; x < grid_x; x++) { for (int y = 0; y < grid_y; y++) { Rectangle temp = new Rectangle(); temp.xProperty().bind(root.heightProperty().divide(grid_x).multiply(x)); temp.yProperty().bind(root.heightProperty().divide(grid_x).multiply(y)); temp.heightProperty().bind(root.heightProperty().divide(grid_x)); temp.widthProperty().bind(temp.heightProperty()); root.getChildren().add(temp); } } stage.setScene(new Scene(root, 500, 500)); stage.show(); }
Pane root = new Pane(); Rectangle rect = new Rectangle(40, 20, 50, 100); rect.setRotate(90); Ellipse ellipse = new Ellipse(450, 450, 50, 25); ellipse.setRotate(45); Circle circle = new Circle(250, 250, 50); root.getChildren().addAll(rect, ellipse, circle); rect.setCursor(Cursor.HAND); circle.setCursor(Cursor.HAND); ellipse.setCursor(Cursor.HAND); root.setOnMousePressed(e -> { Node target = (Node) e.getTarget(); if (target != root) { }); root.setOnMouseDragged(evt -> { if (selected != null) { selected.setTranslateX(evt.getX() - offset.getX() + translateStart.getX()); primaryStage.setScene(scene); primaryStage.show();
public void start(Stage primaryStage) { Pane pane = new Pane(); Rectangle rectangle = new Rectangle( 100.0, i*25.0 + 80.0, 20.0, 20.0); rectangle.setStroke(Color.BLACK); rectangle.setFill(Color.LIGHTGRAY); pane.getChildren().add(group); primaryStage.setScene(new Scene( pane, 640, 480)); primaryStage.show();
primaryStage.setTitle("AnimationTest"); Pane pane = new Pane(); Rectangle rect = new Rectangle(0,0,100,100); pane.getChildren().add(rect); TranslateTransition transition =new TranslateTransition(Duration.millis(1000),rect); transition.setByX(100); Button button = new Button("StartAnimation"); button.setOnAction((e)->{ transition.play(); }); VBox layout = new VBox(); layout.getChildren().addAll(pane, button); Scene scene = new Scene(layout, 600, 600); primaryStage.setScene(scene); primaryStage.show();
Pane pane = new Pane(); Group group = new Group(); Rectangle rect1 = new Rectangle(100, 100, 100, 100); Rectangle rect2 = new Rectangle(100, 100, 100, 100); Rectangle rect3 = new Rectangle(200, 200, 100, 100); Rectangle rect4 = new Rectangle(200, 200, 100, 100); rect1.setFill(Color.BLUE); pane.getChildren().addAll(rect2, rect4);
public static Pane makeGrid(int n){ double width = GridMaker.SCREEN_SIZE/n; Pane p = new Pane(); Rectangle [][] rec = new Rectangle [n][n]; for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ rec[i][j] = new Rectangle(); rec[i][j].setX(i * width); rec[i][j].setY(j * width); rec[i][j].setWidth(width); rec[i][j].setHeight(width); rec[i][j].setFill(null); rec[i][j].setStroke(Color.BLACK); p.getChildren().add(rec[i][j]); } } return p; }