下面列出了javafx.scene.layout.AnchorPane#setPrefSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static Node createIconContent() {
StackPane sp = new StackPane();
AnchorPane anchorPane = new AnchorPane();
Rectangle rectangle = new Rectangle(62, 62, Color.LIGHTGREY);
rectangle.setStroke(Color.BLACK);
anchorPane.setPrefSize(rectangle.getWidth(), rectangle.getHeight());
Rectangle r1 = new Rectangle(14, 14, Color.web("#1c89f4"));
Rectangle r2 = new Rectangle(45, 10, Color.web("#349b00"));
Rectangle r3 = new Rectangle(35, 14, Color.web("#349b00"));
anchorPane.getChildren().addAll(r1, r2, r3);
AnchorPane.setTopAnchor(r1, Double.valueOf(1));
AnchorPane.setLeftAnchor(r1, Double.valueOf(1));
AnchorPane.setTopAnchor(r2, Double.valueOf(20));
AnchorPane.setLeftAnchor(r2, Double.valueOf(1));
AnchorPane.setBottomAnchor(r3, Double.valueOf(1));
AnchorPane.setRightAnchor(r3, Double.valueOf(5));
sp.getChildren().addAll(rectangle, anchorPane);
return new Group(sp);
}
public static Node createIconContent() {
StackPane sp = new StackPane();
AnchorPane anchorPane = new AnchorPane();
Rectangle rectangle = new Rectangle(62, 62, Color.LIGHTGREY);
rectangle.setStroke(Color.BLACK);
anchorPane.setPrefSize(rectangle.getWidth(), rectangle.getHeight());
Rectangle r1 = new Rectangle(14, 14, Color.web("#1c89f4"));
Rectangle r2 = new Rectangle(45, 10, Color.web("#349b00"));
Rectangle r3 = new Rectangle(35, 14, Color.web("#349b00"));
anchorPane.getChildren().addAll(r1, r2, r3);
AnchorPane.setTopAnchor(r1, Double.valueOf(1));
AnchorPane.setLeftAnchor(r1, Double.valueOf(1));
AnchorPane.setTopAnchor(r2, Double.valueOf(20));
AnchorPane.setLeftAnchor(r2, Double.valueOf(1));
AnchorPane.setBottomAnchor(r3, Double.valueOf(1));
AnchorPane.setRightAnchor(r3, Double.valueOf(5));
sp.getChildren().addAll(rectangle, anchorPane);
return new Group(sp);
}
@Override public void start(Stage stage) {
AnchorPane pane = new AnchorPane(xAxisBottom, yAxisLeft);
pane.setPadding(new Insets(10));
pane.setPrefSize(400, 400);
Scene scene = new Scene(pane);
stage.setTitle("Title");
stage.setScene(scene);
stage.show();
}
@Override public void start(Stage stage) {
AnchorPane pane = new AnchorPane(xAxisBottom, xAxisTop, yAxisLeft, yAxisRight);
pane.setPadding(new Insets(10));
pane.setPrefSize(400, 400);
Scene scene = new Scene(pane);
stage.setTitle("Title");
stage.setScene(scene);
stage.show();
}
@Override
public void start(Stage primaryStage) throws Exception {
hostServices = getHostServices();
//Creat main Pane Layout
AnchorPane mainPane = new AnchorPane();
mainPane.setPrefSize(800, 600);
//Creat MDI Canvas Container
DesktopPane desktopPane = new DesktopPane();
//Fit it to the main Pane
AnchorPane.setBottomAnchor(desktopPane, 0d);
AnchorPane.setLeftAnchor(desktopPane, 0d);
AnchorPane.setTopAnchor(desktopPane, 25d);//Button snapTo
AnchorPane.setRightAnchor(desktopPane, 0d);
//Put the container Into the main pane
mainPane.getChildren().add(desktopPane);
//Create a 'New MDI Window' Button
Button newWindowButton = new Button("New Window");
//set the button action
newWindowButton.setOnAction(event -> {
Node content = null;
try {
content = FXMLLoader.load(getClass().getResource("/MyContent.fxml"));
} catch (Exception e) {
throw new RuntimeException(e);
}
count++;
//Create a new window
InternalWindow internalWindow = new InternalWindow("UniqueID" + count,
new FontIcon("mdi-application:20:RED"),
"Title " + count,
content);
//Add it to the container
desktopPane.addInternalWindow(internalWindow);
});
//Put it into the main pane
mainPane.getChildren().add(newWindowButton);
primaryStage.setScene(new Scene(mainPane));
primaryStage.show();
}