繁体   English   中英

SceneBuilder中的JavaFX组件位置问题

[英]JavaFX component position problem in SceneBuilder

即使我通过拖放将按钮的位置设置在scenebuilder的右下角,程序运行时也不存在。 没有像窗格容器的顶侧边缘那样只出现在底侧的问题。 有束缚的问题还是什么? 我该如何解决这个问题? 谢谢你的帮助。

<?import javafx.scene.image.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.chart.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<Pane centerShape="false" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" pickOnBounds="false" prefHeight="600.0" prefWidth="800.0" scaleShape="false" styleClass="paneMainPage" stylesheets="@StyleSheets/mainStage_stylesheet.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ControllerMainScene">
   <children>
      <Circle fx:id="internetConnectionCheck" centerY="556.0" fill="#20ff1f" layoutX="735.0" layoutY="31.0" radius="9.0" stroke="BLACK" strokeType="INSIDE" />
      <Slider fx:id="delaySlider" layoutX="14.0" layoutY="568.0" majorTickUnit="1.0" max="10.0" min="1.0" minorTickCount="0" showTickLabels="true" showTickMarks="true" snapToTicks="true" value="1.0">
         <tooltip>
            <Tooltip text="Sets delay time to update currency table" />
         </tooltip>
      </Slider>
      <Text layoutX="14.0" layoutY="564.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Delay (s)" />
      <Button fx:id="exitButton" layoutX="751.0" layoutY="570.0" mnemonicParsing="false" prefHeight="32.0" prefWidth="50.0" text="Exit" />
      <Pane fx:id="dollarCurrencyPane" prefHeight="102.0" prefWidth="140.0">
         <children>
            <Label alignment="CENTER" prefHeight="32.0" prefWidth="140.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="Dollar" />
            <Label alignment="CENTER" layoutY="30.0" prefHeight="18.0" prefWidth="70.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="Buy" />
            <Label alignment="CENTER" layoutX="70.0" layoutY="30.0" prefHeight="18.0" prefWidth="70.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="Sell" />
            <Label fx:id="dollarBuyLabel" alignment="CENTER" layoutY="48.0" prefHeight="26.0" prefWidth="70.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="0.0" />
            <Label fx:id="dollarSellLabel" alignment="CENTER" layoutX="70.0" layoutY="48.0" minWidth="-Infinity" prefHeight="26.0" prefWidth="70.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="0.0" />
            <Label fx:id="dollarBuyRate" layoutY="73.0" prefHeight="26.0" prefWidth="70.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="\%0.00" />
            <Polygon fx:id="dollarBuyRatePoly" fill="#33FE01" layoutX="60.0" layoutY="53.0" stroke="BLACK" strokeType="INSIDE">
               <points>
                <Double fx:value="-5.0" />
                <Double fx:value="40.0" />
                <Double fx:value="5.0" />
                <Double fx:value="40.0" />
                <Double fx:value="0.0" />
                <Double fx:value="25.0" />
               </points>
            </Polygon>
            <Rectangle fx:id="dollarBuyRateRect" arcHeight="5.0" arcWidth="5.0" fill="WHITE" height="4.0" layoutX="48.0" layoutY="85.0" stroke="BLACK" strokeType="INSIDE" width="18.0" />
            <Label fx:id="dollarSellRate" layoutX="70.0" layoutY="73.0" prefHeight="26.0" prefWidth="70.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="\%0.00" />
            <Polygon fx:id="dollarSellRatePoly" fill="#33FE01" layoutX="130.0" layoutY="53.0" stroke="BLACK" strokeType="INSIDE">
              <points>
                <Double fx:value="-5.0" />
                <Double fx:value="40.0" />
                <Double fx:value="5.0" />
                <Double fx:value="40.0" />
                <Double fx:value="0.0" />
                <Double fx:value="25.0" />
              </points>
            </Polygon>
            <Rectangle fx:id="dollarSellRateRect" arcHeight="5.0" arcWidth="5.0" fill="WHITE" height="4.0" layoutX="118.0" layoutY="85.0" stroke="BLACK" strokeType="INSIDE" width="18.0" />
         </children>
      </Pane>
      <Pane fx:id="euroCurrencyPane" layoutY="101.0" prefHeight="102.0" prefWidth="140.0">
         <children>
            <Label alignment="CENTER" layoutY="-2.0" prefHeight="32.0" prefWidth="140.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="Euro" />
            <Label alignment="CENTER" layoutX="70.0" layoutY="30.0" prefHeight="18.0" prefWidth="70.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="Sell" />
            <Label alignment="CENTER" layoutY="30.0" prefHeight="18.0" prefWidth="70.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="Buy" />
            <Label fx:id="euroSellLabel" alignment="CENTER" layoutX="70.0" layoutY="48.0" minWidth="-Infinity" prefHeight="26.0" prefWidth="70.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="0.0" />
            <Label fx:id="euroBuyLabel" alignment="CENTER" layoutY="48.0" prefHeight="26.0" prefWidth="70.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="0.0" />
            <Label fx:id="euroSellRate" layoutX="70.0" layoutY="74.0" prefHeight="26.0" prefWidth="70.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="\%0.00" />
            <Label fx:id="euroBuyRate" layoutY="74.0" prefHeight="26.0" prefWidth="70.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="\%0.00" />
            <Rectangle fx:id="euroBuyRateRect" arcHeight="5.0" arcWidth="5.0" fill="WHITE" height="4.0" layoutX="48.0" layoutY="87.0" stroke="BLACK" strokeType="INSIDE" width="18.0" />
            <Polygon fx:id="euroBuyRatePoly" fill="#33FE01" layoutX="60.0" layoutY="55.0" stroke="BLACK" strokeType="INSIDE">
               <points>
                  <Double fx:value="-5.0" />
                  <Double fx:value="40.0" />
                  <Double fx:value="5.0" />
                  <Double fx:value="40.0" />
                  <Double fx:value="0.0" />
                  <Double fx:value="25.0" />
               </points>
            </Polygon>
            <Polygon fx:id="euroSellRatePoly" fill="#33FE01" layoutX="130.0" layoutY="55.0" stroke="BLACK" strokeType="INSIDE">
               <points>
                  <Double fx:value="-5.0" />
                  <Double fx:value="40.0" />
                  <Double fx:value="5.0" />
                  <Double fx:value="40.0" />
                  <Double fx:value="0.0" />
                  <Double fx:value="25.0" />
               </points>
            </Polygon>
            <Rectangle fx:id="euroSellRateRect" arcHeight="5.0" arcWidth="5.0" fill="WHITE" height="4.0" layoutX="118.0" layoutY="87.0" stroke="BLACK" strokeType="INSIDE" width="18.0" />
         </children>
      </Pane>
      <Pane fx:id="gbdCurrencyPane" layoutY="201.0" prefHeight="102.0" prefWidth="140.0">
         <children>
            <Label alignment="CENTER" prefHeight="32.0" prefWidth="140.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="GBP" />
            <Label fx:id="gbpBuyLabel" alignment="CENTER" layoutY="50.0" prefHeight="26.0" prefWidth="70.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="0.0" />
            <Label fx:id="gbpSellLabel" alignment="CENTER" layoutX="70.0" layoutY="50.0" minWidth="-Infinity" prefHeight="26.0" prefWidth="70.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="0.0" />
            <Label alignment="CENTER" layoutY="32.0" prefHeight="18.0" prefWidth="70.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="Buy" />
            <Label alignment="CENTER" layoutX="70.0" layoutY="32.0" prefHeight="18.0" prefWidth="70.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="Sell" />
            <Label fx:id="gbpBuyRate" layoutY="75.0" prefHeight="26.0" prefWidth="70.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="\%0.00" />
            <Label fx:id="gbpSellRate" layoutX="70.0" layoutY="75.0" prefHeight="26.0" prefWidth="70.0" styleClass="labelCurrencyTable" stylesheets="@StyleSheets/mainStage_stylesheet.css" text="\%0.00" />
            <Rectangle fx:id="gbpSellRateRect" arcHeight="5.0" arcWidth="5.0" fill="WHITE" height="4.0" layoutX="118.0" layoutY="88.0" stroke="BLACK" strokeType="INSIDE" width="18.0" />
            <Polygon fx:id="gbpSellRatePoly" fill="#33FE01" layoutX="130.0" layoutY="56.0" stroke="BLACK" strokeType="INSIDE">
               <points>
                  <Double fx:value="-5.0" />
                  <Double fx:value="40.0" />
                  <Double fx:value="5.0" />
                  <Double fx:value="40.0" />
                  <Double fx:value="0.0" />
                  <Double fx:value="25.0" />
               </points>
            </Polygon>
            <Polygon fx:id="gbpBuyRatePoly" fill="#33FE01" layoutX="60.0" layoutY="56.0" stroke="BLACK" strokeType="INSIDE">
               <points>
                  <Double fx:value="-5.0" />
                  <Double fx:value="40.0" />
                  <Double fx:value="5.0" />
                  <Double fx:value="40.0" />
                  <Double fx:value="0.0" />
                  <Double fx:value="25.0" />
               </points>
            </Polygon>
            <Rectangle fx:id="gbpBuyRateRect" arcHeight="5.0" arcWidth="5.0" fill="WHITE" height="4.0" layoutX="48.0" layoutY="88.0" stroke="BLACK" strokeType="INSIDE" width="18.0" />
         </children>
      </Pane>
   </children>
</Pane>

图片。

图片

以我的经验,Scene Builder不是判断GUI外观的可靠来源。 它总是在最外层元素的边缘处切掉布局,忽略您在最外层元素上设置的任何边距或填充。

我建议总是编译你的程序,看它是如何看起来的(我知道,这样做起来比较慢,但更可靠)。

也许您的CSS类paneMainPage设置了一些填充? 或者你为mainStage_stylesheet.css里面的CSS类中的每个按钮添加边距?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM