簡體   English   中英

在父BorderPane中居中並調整ImageView的大小

[英]Center and resize ImageView in parent BorderPane

我有以下FXML:

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

<?import javafx.scene.image.*?>
<?import javafx.scene.effect.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>

<BorderPane fx:id="mainBorderPane" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.mho.livepicture.server.ui.presenter.UIPresenter">
   <top>
      <MenuBar BorderPane.alignment="CENTER">
        <menus>
          <Menu mnemonicParsing="false" text="Datei">
            <items>
              <MenuItem mnemonicParsing="false" onAction="#exit" text="Beenden" />
            </items>
          </Menu>
          <Menu mnemonicParsing="false" text="Hilfe">
            <items>
              <MenuItem mnemonicParsing="false" text="Über..." />
            </items>
          </Menu>
        </menus>
      </MenuBar>
   </top>
   <bottom>
      <HBox alignment="CENTER_RIGHT" spacing="6.0" BorderPane.alignment="CENTER_RIGHT">
         <children>
            <Button fx:id="startStopServerButton" mnemonicParsing="false" onAction="#startStopServer" text="Server starten" />
            <Button mnemonicParsing="false" onAction="#exit" text="Beenden">
               <opaqueInsets>
                  <Insets />
               </opaqueInsets>
               <HBox.margin>
                  <Insets />
               </HBox.margin>
            </Button>
         </children>
         <BorderPane.margin>
            <Insets bottom="6.0" left="6.0" right="6.0" top="6.0" />
         </BorderPane.margin>
      </HBox>
   </bottom>
   <center>
      <ImageView fx:id="imageView" pickOnBounds="true" preserveRatio="true" BorderPane.alignment="CENTER" />
   </center>
</BorderPane>

在演示者(控制器)中,我執行以下操作以動態居中並調整圖像大小:

mainBorderPane.prefWidthProperty().bind(primaryStage.widthProperty());
mainBorderPane.prefHeightProperty().bind(primaryStage.heightProperty());

imageView.setImage(new Image(MAIN_ICON_BLACK_URL));
imageView.fitWidthProperty().bind(mainBorderPane.widthProperty());
imageView.fitHeightProperty().bind(mainBorderPane.heightProperty());

我不知道如何使ImageView調整BorderPane中心中可用空間的大小。 它始終使用舞台/場景的整個可用大小。

嘗試在BorderPane leftright添加一個節點。 這樣可以防止ImageView占據整個空間。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM