简体   繁体   中英

JavaFX component position problem in SceneBuilder

Even if I set position of button to right-bottom corner in scenebuilder by drag and drop, it doesn't be there when program runs. There isn't any problem like that with top side edge of pane container it occurs just at bottom side. Is there a bound problem or what? How can I fix that? Thanks for helps.

<?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>

Image.

图片

In my experience, the Scene Builder is not a reliable source for judging how the GUI looks. It always cuts the layout off at the edges of the outer most elements, ignoring any margins or paddings you set on the outer most elements.

I would suggest to always compile your program to see, how it really looks (I know, this is slower to work with, but far more reliable).

Maybe your CSS class paneMainPage sets some paddings? Or you add margins to every button in a CSS class inside of mainStage_stylesheet.css ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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