2

何らかの理由で、ウィンドウのサイズを変更しても、ガスポンプヘッダーとコーヒーハウスヘッダーの両方のペインが伸びません。私はJavaFX Scene Builderを使用しています.JavaFXは初めてです(答えがかなり基本的な場合に備えて...)

ペインを横 (左右) に伸ばして、ウィンドウの幅全体を埋めるようにします。

これが私のFXMLです

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

<?import java.lang.*?>
<?import java.net.*?>
<?import java.util.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>

<AnchorPane prefHeight="768.0" prefWidth="1024.0" xmlns:fx="http://javafx.com/fxml">
  <children>
    <HBox id="action-buttons-section" alignment="CENTER_LEFT" layoutY="14.0" spacing="5.0" 

AnchorPane.leftAnchor="14.0">
      <children>
        <Button mnemonicParsing="false" text="Add Customer" />
        <Button mnemonicParsing="false" text="Move Customer" />
      </children>
    </HBox>
    <HBox id="fuel-pool-section" alignment="CENTER_LEFT" layoutY="14.0" spacing="5.0" AnchorPane.rightAnchor="16.0">
      <children>
        <Label text="Main Fuel Pool" />
        <ProgressBar prefHeight="20.0" prefWidth="200.0" progress="0.0" />
        <Button mnemonicParsing="false" text="Fill" />
      </children>
    </HBox>
    <VBox alignment="CENTER" spacing="10.0" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="44.0">
      <children>
        <VBox alignment="CENTER" spacing="5.0">
          <children>
            <Pane id="gas-pumps-header" prefHeight="100.0" prefWidth="996.0"> <!-- first one -->
              <children>
                <Label layoutX="14.0" layoutY="15.0" text="Gas Pumps">
                  <font>
                    <Font name="System Bold" size="16.0" fx:id="x2" />
                  </font>
                </Label>
                <HBox id="gas-pumps-income-section" alignment="CENTER_RIGHT" layoutX="893.0" layoutY="15.0" spacing="5.0">
                  <children>
                    <Label text="Income">
                      <font>
                        <Font size="14.0" fx:id="x1" />
                      </font>
                    </Label>
                    <Label fx:id="gasPumpsIncomeValue" font="$x1" text="Value" />
                  </children>
                </HBox>
              </children>
            </Pane>
            <HBox id="gas-pumps-section" prefHeight="378.0" prefWidth="996.0" styleClass="layout" VBox.vgrow="ALWAYS">
              <padding>
                <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" fx:id="x3" />
              </padding>
            </HBox>
          </children>
        </VBox>
        <VBox alignment="CENTER" spacing="5.0">
          <children>
            <Pane id="coffee-house-header" prefHeight="100.0" prefWidth="996.0"> <!-- second one -->
              <children>
                <Label font="$x2" layoutX="14.0" layoutY="15.0" text="Coffee House" />
                <HBox id="coffee-house-income-section" alignment="CENTER_RIGHT" layoutX="893.0" layoutY="15.0" spacing="5.0">
                  <children>
                    <Label font="$x1" text="Income" />
                    <Label fx:id="coffeeHouseIncomeValue" font="$x1" text="Value" />
                  </children>
                </HBox>
              </children>
            </Pane>
            <HBox id="coffee-house-section" padding="$x3" prefHeight="378.0" prefWidth="996.0" styleClass="layout" VBox.vgrow="ALWAYS" />
          </children>
        </VBox>
      </children>
    </VBox>
  </children>
  <stylesheets>
    <URL value="@style.css" />
  </stylesheets>
</AnchorPane>
4

2 に答える 2

1

さまざまな種類のペインで遊んだ後、なんとか機能させることができました。

BorderPane を使用し、BorderPane の左右に子ノードを追加しました。ウィンドウのサイズを変更すると、すべての要素が開始レイアウトの相対位置に再配置されます。

これがBorderPane部分です

<BorderPane id="gas-pumps-header" VBox.vgrow="SOMETIMES">
    <left>
        <Label text="Gas Pumps" BorderPane.alignment="CENTER_LEFT">
            <font>
                <Font name="System Bold" size="16.0" fx:id="x2" />
            </font>
        </Label>
    </left>
    <padding>
        <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" fx:id="x3" />
    </padding>
    <right>
        <HBox id="gas-pumps-income-section" alignment="CENTER_RIGHT" spacing="5.0" BorderPane.alignment="CENTER_RIGHT">
            <children>
                <Label text="Income">
                    <font>
                        <Font size="14.0" fx:id="x1" />
                    </font>
                </Label>
                <Label fx:id="gasPumpsIncomeValue" font="$x1" text="Value" />
            </children>
        </HBox>
    </right>              
</BorderPane>
于 2013-08-18T23:31:46.403 に答える
0

アプリケーション ウィンドウのサイズが変更されると、gas-pumps-header はすでに自動的にサイズ変更されています。

SceneBuilder で fxml ファイルを開き (私は win7 で 1.1-b28 を使用しました)、SceneBuilder Hierarchy ペインの Gas-pumps-header ペインをクリックし、スタイルを -fx-border-color: red; に設定します。SceneBuilder メニュー項目のプレビュー | を選択します。プレビューとウィンドウを表示し、プレビュー ウィンドウのサイズを変更すると、プレビュー ウィンドウのサイズを変更すると、ガスポンプ ヘッダーの赤い境界線のサイズが変更されます。

おそらく、あなたの質問からは理解できないレイアウトに問題があるため、上記はそれほど役に立たないと確信しています。

一般に、ほとんどのレイアウトでは Pane ではなく、Pane の適切なサブクラスを使用することをお勧めします。これは、Pane サブクラスがレイアウト作業により多くの作業を行うためです。おそらく、あなたの場合は HBox の方が適切でしょう。

于 2013-08-16T23:36:41.823 に答える