Эта вкладка для моего приложения Javafx 17 состоит из 2 пограничных панелей.
Основная боль для макетов, которая содержит обзор в правой части и вторую пограничную панель в центре.
Эта граница состоит из Изображение в центре, сделанная на заказ панель FileView Im работает внизу и текстовый поле справа. < /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>
Я получаю поведение, показанное на двух изображениях, изображение изменяется по размеру, и, следовательно, все представление не является статичным, я хочу, чтобы элемент изображения имел полностью фиксированный размер, определяемый Высота и ширина окна.
Я попробовал этот подход, который должен был поместить изображение в стекпан и попытаться установить свою мин и максимальную ширину и высоту, чтобы связать ширину и высоту основного макета. < / 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>
Но теперь, как пограничный панель, в котором находится изображение, имеет размер 0 x 0, я просто не могу найти способ, чтобы изображение имело фиксированный размер, пропорциональный размеру окна, его в Таким образом, все элементы остаются фиксированными на своих позициях. 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>
Это привело к тому, что изображение является полным размером пограничного панела и полностью охватывающим другие элементы, кроме вида дерева слева. Показатели фотографий выпуска: https://imgur.com/a/wo0phma
Подробнее здесь: https://stackoverflow.com/questions/794 ... a-set-size