Diese Registerkarte für meine Javafx 17 -App besteht aus 2 Grenzflächen. Ein ImageView in der Mitte, ein maßgeschneidertes Fileview -Bereich im Boden und ein Textfeld rechts. < /p>
public addview() {
mainLayout = new BorderPane();
subLayout1 = new BorderPane();
directoryTreeView = new TreeView();
directoryTreeView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
imageView = new ImageView();
imageView.setFitHeight(520);
imageView.setFitWidth(600);
imageView.setPreserveRatio(true);
imageView.setSmooth(true);
imageView.setCache(true);
textArea = new TextArea();
textArea.setWrapText(true);
textArea.setEditable(false);
// Create a navigation bar with Back and Home buttons
navigationBar = new HBox(10);
navigationBar.setAlignment(Pos.CENTER_LEFT); // Align buttons to the left
navigationBar.getStyleClass().add("navigation-bar"); // Assign CSS class to the bar
// Back button with arrow icon
ImageView backIcon = new ImageView(new Image("/resources/icons/back.png"));
backIcon.setFitHeight(16);
backIcon.setFitWidth(16);
backButton = new Button("", backIcon); // Add text and icon
backButton.setId("navigation-button");
// Home button with house icon
ImageView homeIcon = new ImageView(new Image("/resources/icons/home.png"));
homeIcon.setFitHeight(16);
homeIcon.setFitWidth(16);
homeButton = new Button("", homeIcon); // Add text and icon
homeButton.setId("navigation-button");
// In the constructor after homeButton
previewAnimationButton = new Button("Preview Animation");
previewAnimationButton.setId("preview-animation-button");
previewAnimationButton.setVisible(false); // Initially hidden
previewAnimationButton.setManaged(false);
// Add Stop Preview button (initially hidden)
stopAnimationButton = new Button("Stop Preview");
stopAnimationButton.setId("stop-animation-button");
stopAnimationButton.setVisible(false); // Initially hidden
stopAnimationButton.setManaged(false);
// Add buttons to the navigation bar
navigationBar.getChildren().addAll(backButton, homeButton, previewAnimationButton, stopAnimationButton);
fileView = new FlowPane();
fileView.setVgap(10);
fileView.setHgap(10);
fileView.setPrefWrapLength(0);
fileScrollPane = new ScrollPane(fileView);
fileScrollPane.setFitToWidth(true);
folderViewContent = new VBox(0, navigationBar, fileScrollPane);
subLayout1.setCenter(imageView);
subLayout1.setRight(textArea);
subLayout1.setBottom(folderViewContent);
mainLayout.setLeft(directoryTreeView);
mainLayout.setCenter(subLayout1);
applyCSS();
}
< /code>
Ich erhalte das in den beiden Bildern gezeigte Verhalten, das Bild verändert sich und somit ist die gesamte Ansicht nicht statisch, ich möchte, dass das Bildelement eine vollständig feste Größe von der bestimmt wird Höhe und Breite des Fensters. p>
imageView.setFitHeight(520);
imageView.setFitWidth(600);
imageView.setPreserveRatio(true);
imageView.setSmooth(true);
imageView.setCache(true);
// Wrap ImageView inside a StackPane
imageContainer = new StackPane(imageView);
// Force a fixed size for the center of subLayout1
// Bind its width and height to 60% of window width & 65% of window height
imageContainer.prefWidthProperty().bind(mainLayout.widthProperty().multiply(0.60));
imageContainer.maxWidthProperty().bind(mainLayout.widthProperty().multiply(0.60));
imageContainer.minWidthProperty().bind(mainLayout.widthProperty().multiply(0.60));
// Enforce exactly 65% of window height
imageContainer.prefHeightProperty().bind(mainLayout.heightProperty().multiply(0.65));
imageContainer.maxHeightProperty().bind(mainLayout.heightProperty().multiply(0.65));
imageContainer.minHeightProperty().bind(mainLayout.heightProperty().multiply(0.65));
// Ensure subLayout1 respects this size
subLayout1.setCenter(imageContainer);
VBox.setVgrow(imageContainer, Priority.NEVER); // Prevent it from growing
< /code>
Aber jetzt hat das BorderPane, in dem das ImageView sitzt Also bleiben alle Elemente in ihren Positionen behoben. imageView = new ImageView();
imageView.setFitHeight(600);
imageView.setFitWidth(520);
imageView.setPreserveRatio(true);
imageView.setSmooth(true);
imageView.setCache(true);
// Wrap ImageView inside a StackPane
imageContainer = new StackPane(imageView);
imageView.fitWidthProperty().bind(imageContainer.widthProperty());
imageView.fitHeightProperty().bind(imageContainer.heightProperty());
imageContainer.prefWidthProperty().bind(mainLayout.widthProperty().multiply(0.60));
imageContainer.prefHeightProperty().bind(mainLayout.heightProperty().multiply(0.65));
< /code>
Dies führte dazu, dass das Bild die volle Größe des BorderPane war und die anderen Elemente mit Ausnahme der Baumansicht links vollständig abdeckte. Bilder des Problems zeigen: https://imgur.com/a/wo0phma
Ich möchte eine Imageview in einem BorderPane -Zentrum erstellen, die eine festgelegte Größe haben ⇐ Java
-
- Similar Topics
- Replies
- Views
- Last post