2017-10-17 134 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>