package renderingbug; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.ScrollPane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; public class Main extends Application { Rectangle rearRectangle; Rectangle rearRectangleClickIndicator; ScrollPane scrollPane; Rectangle rectangle4; double GtextHeight; double GtextWidth; double space = 10.0; ObservableList XYparams; double centerX; double centerY; double textWidth; double textHeight; double rectSide; double sX; double sY; double kX; double kY; public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) throws Exception { space = 10.0; XYparams = getXYparams(1, 3, 444, 333, space); rectSide = XYparams.get(0); sX = XYparams.get(1); sY = XYparams.get(2); kX = XYparams.get(3); kY = XYparams.get(4); centerX = ((kX + 1) * sX + rectSide * kX) / (2 * kX); centerY = ((kY + 1) * sY + rectSide * kY) / (2 * kY); initRearRectangle(); Group top_container = new Group(); top_container.setTranslateX(centerX - rectSide / 2 + space); top_container.setTranslateY(centerY - rectSide / 2 + space); initScrollPane(); Group content = initContent(); scrollPane.setContent(content); top_container.getChildren().clear(); top_container.getChildren().addAll(scrollPane); Scene scene = new Scene(new Group(), 444, 333); stage.setScene(scene); ((Group) scene.getRoot()).getChildren().clear(); ((Group) scene.getRoot()).getChildren().addAll(rearRectangle); ((Group) scene.getRoot()).getChildren().addAll(top_container); stage.show(); } public ObservableList getXYparams(double kX, double kY, double w, double h, double space) { /* * The Node is a square * result [0] - z width/height of Node * result [1] - space between Nodes in X * result [2] - space between Nodes in Y * result [3] - number of Nodes in X * result [4] - number of Nodes in Y * result [5] - width of the Stage * result [6] - height of the Stage */ ObservableList result = FXCollections.observableArrayList(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); result.set(3, kX); result.set(4, kY); result.set(5, w); result.set(6, h); double zX = (w - (kX + 1) * space) / kX; double zY = (h - (kY + 1) * space) / kY; double z = zX; if (zX > zY) { z = zY; } double spaceX = (w - z * kX) / (kX + 1); double spaceY = (h - z * kY) / (kY + 1); result.set(1, spaceX); result.set(2, spaceY); result.set(0, z); return result; } private void initRearRectangle() { rearRectangle = new Rectangle(centerX - rectSide / 2, centerY - rectSide / 2, rectSide, rectSide); rearRectangle.setFill(Color.GREY); rearRectangleClickIndicator = new Rectangle(centerX - rectSide / 2, centerY + rectSide / 2 + 1, sY - 2, sY - 2); } private void initScrollPane() { scrollPane = new ScrollPane(); scrollPane.setPrefWidth(rectSide - 2 * space); scrollPane.setPrefHeight(rectSide - 2 * space); } private Group initContent() { Group content = new Group(); Rectangle rectangle2 = new Rectangle(rectSide - 2 * space - 3, rectSide - 2 * space - 3); rectangle2.setFill(Color.MAGENTA); Rectangle rectangle3 = new Rectangle(20.0, 20.0, rectSide - 2 * space - 40, rectSide - 2 * space - 40); rectangle3.setFill(Color.YELLOW); content.getChildren().clear(); content.getChildren().addAll(rectangle2, rectangle3); return content; } }