2017-10-17 140 views
-1

我有一個按鈕大小的問題。當我增加窗口的大小時, 按鈕重疊。爲了避免這種情況,我嘗試了很多thnigs,例如將每個按鈕都放在一個anchorpane中,但沒有成功。窗口大小增加時按鈕的重疊 - javafx - fxml

這裏是用於按鈕的FXML碼 「DEVIS」 例如:

<AnchorPane layoutX="5.0" layoutY="71.0" maxHeight="61.25" prefHeight="58.0" prefWidth="206.0" AnchorPane.bottomAnchor="116.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="71.0"> 
    <children> 
     <Button fx:id="devis" maxHeight="65.0" mnemonicParsing="false" onAction="#selectViewDevis" prefHeight="65.0" prefWidth="206.0" text="Devis" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> 
     <font> 
      <Font size="14.0" /> 
     </font> 
     </Button> 
    </children> 
</AnchorPane> 

我的窗口的2個圖像之前和增加

Before increasing

After increasing

後感謝您的幫助,

Aaron

+1

您的代碼只有一個按鈕。另外,當用戶增加窗口大小時,你真的希望發生什麼? –

+0

我的代碼有更多的按鈕。我想把它縮短。 – AaronLbk

+0

我並不是想要變得困難,但是如果您只提供其中只有一個按鈕的代碼,您怎麼可能認爲您可以提供顯示按鈕重疊的代碼?怎麼有人可以告訴你你在做什麼錯?創建一個[MCVE]:你應該可以用(可能)兩個按鈕來做到這一點,並提供一個完整的,可執行的例子,重現問題(但顯然,不是你的整個項目)。解釋它在做什麼以及你如何真正希望它的行爲。確保你已經閱讀了基本的教程和佈局文件。 –

回答

0

嘗試使用'VBox'

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

<?import javafx.scene.control.Button?> 
<?import javafx.scene.control.SplitPane?> 
<?import javafx.scene.image.ImageView?> 
<?import javafx.scene.layout.AnchorPane?> 
<?import javafx.scene.layout.StackPane?> 
<?import javafx.scene.layout.VBox?> 


<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1"> 
    <children> 
     <SplitPane dividerPositions="0.35451505016722407" layoutX="189.0" layoutY="167.0" prefHeight="160.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> 
     <items> 
      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"> 
       <children> 
        <VBox layoutX="24.0" layoutY="14.0" minWidth="200.0" prefHeight="200.0" prefWidth="100.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> 
        <children> 
         <StackPane prefHeight="150.0" prefWidth="200.0"> 
          <children> 
           <ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" /> 
          </children> 
         </StackPane> 
         <Button maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Button" /> 
         <Button maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Button" /> 
         <Button maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Button" /> 
        </children> 
        </VBox> 
       </children> 
      </AnchorPane> 
      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" /> 
     </items> 
     </SplitPane> 
    </children> 
</AnchorPane>