gpt4 book ai didi

java - 如何将 ImageView 锚定到其 BorderPane 区域的中心?

转载 作者:行者123 更新时间:2023-12-02 12:23:26 25 4
gpt4 key购买 nike

我有一个带有 ImageView 的 BorderPane 布局,如下所示,但 ImageView 始终锚定在左上角,并且在我调整窗口大小时保持在那里。我希望 ImageView 将 anchor 保持在它所绑定(bind)的部分的中心(红色框)。使用 FXML 可以吗?

enter image description here

FXML:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.Group?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.*?>

<VBox prefWidth="800.0" prefHeight="600.0" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1">

<BorderPane xmlns:fx="http://javafx.com/fxml" VBox.vgrow="ALWAYS">
<top>
<VBox alignment="TOP_CENTER">
<ToolBar minHeight="50.0" prefHeight="50.0" prefWidth="800.0" stylesheets="@../css/style.css"
GridPane.rowIndex="1">
<ImageView fitHeight="35.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true">
<Image url="@../images/toolbar-logo.png"/>
</ImageView>
</ToolBar>
<MenuBar fx:id="menuBar" prefHeight="0.0" prefWidth="0.0"/>
</VBox>
</top>

<left>
<StackPane prefWidth="230.0" prefHeight="800.0">
<ListView fx:id="listView"/>
</StackPane>
</left>

<center>
<StackPane>
<ScrollPane>
<Group fx:id="selectionGroup">
<ImageView fx:id="mainImageView"/>
</Group>
</ScrollPane>
</StackPane>
</center>

<right>
<TextField promptText="Text" />
</right>
</BorderPane>

</VBox>

最佳答案

更改:

        <StackPane>
<ScrollPane>
<Group fx:id="selectionGroup">
<ImageView fx:id="mainImageView"/>
</Group>
</ScrollPane>
</StackPane>

致:

        <StackPane>
<children>
<ImageView fx:id="mainImageView" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" />
</children>
</StackPane>

您可能需要调整 fitWidthfitHeight 属性。

关于java - 如何将 ImageView 锚定到其 BorderPane 区域的中心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45617497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com