【发布时间】:2020-08-18 14:54:59
【问题描述】:
我正在做一些检查世界时间的应用程序。我想在世界地图上使用单选按钮来代表城市。但是我在将这个按钮放置在我的世界地图上时遇到了问题。有我的 fxml 文件。我怎样才能将这个按钮移动到我想要的 px 数量。有我的 FXML 文件。我在 css 文件中设置了堆栈窗格背景图像。在 main.java 中,我只将 app 设置为不可调整大小。
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.TilePane?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.Label?>
<BorderPane fx:controller="sample.Controller"
xmlns:fx="http://javafx.com/fxml"
stylesheets="@styles.css">
<top>
<TilePane alignment="center" hgap="5" vgap="5">
<padding><Insets top="5" bottom="10" left="5" right="5"/></padding>
<Button text="Europa" />
<Button text="Afryka" />
<Button text="Azja" id="button_three" />
<Button text="Australia" />
<Button text="Ameryka Północna" />
<Button text="Ameryka Południowa"/>
</TilePane>
</top>
<center>
<StackPane id="Europa" prefWidth="700" prefHeight="650" >
<RadioButton text="Londyn" />
<RadioButton text="Warszawa"/>
</StackPane>
</center>
<bottom>
</bottom>
<right>
<VBox alignment="CENTER_LEFT">
<Label text="Your City :"/>
<Label text="Time in your City :"/>
</VBox>
</right>
</BorderPane>
另外,当我尝试这样定位时,它可以工作,但按钮上方和左侧的空间也会激活按钮,所以我猜这不是正确的方式
<center>
<StackPane id="Europa" alignment="TOP_LEFT" prefWidth="700" prefHeight="650" >
<RadioButton text="Londyn" >
<padding><Insets top="50" left="50"/></padding>
</RadioButton>
<RadioButton text="Warszawa"/>
</StackPane>
</center>
【问题讨论】:
标签: java user-interface javafx