JavaFX,在 Stack Pane 上放置单选按钮时出现问题。

huangapple 未分类评论47阅读模式
英文:

JavaFX, Problem with positiong radio buttons over Stack Pane

问题

<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&#243;ł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>
英文:

I've doing some application for checking time on the world. I want use Radio Buttons over the map of the world for representing Cities. But I have a problem with positioning this buttons over my World Map. There is my fxml file. How can i move this button for the amount px I want. There is my FXML file. I set stack Pane background image in css file. In main.java I only set app to not be resizable.

&lt;?import javafx.scene.control.Button?&gt;
&lt;?import javafx.scene.control.RadioButton?&gt;
&lt;?import javafx.scene.layout.BorderPane?&gt;
&lt;?import javafx.scene.layout.TilePane?&gt;
&lt;?import javafx.scene.layout.StackPane?&gt;
&lt;?import javafx.geometry.Insets?&gt;
&lt;?import javafx.scene.layout.VBox?&gt;
&lt;?import javafx.scene.control.Label?&gt;
&lt;BorderPane fx:controller=&quot;sample.Controller&quot;
            xmlns:fx=&quot;http://javafx.com/fxml&quot;
            stylesheets=&quot;@styles.css&quot;&gt;
    &lt;top&gt;
        &lt;TilePane alignment=&quot;center&quot; hgap=&quot;5&quot; vgap=&quot;5&quot;&gt;
        &lt;padding&gt;&lt;Insets top=&quot;5&quot; bottom=&quot;10&quot; left=&quot;5&quot; right=&quot;5&quot;/&gt;&lt;/padding&gt;
            &lt;Button text=&quot;Europa&quot; /&gt;

            &lt;Button text=&quot;Afryka&quot; /&gt;

            &lt;Button text=&quot;Azja&quot; id=&quot;button_three&quot; /&gt;

            &lt;Button text=&quot;Australia&quot; /&gt;

            &lt;Button text=&quot;Ameryka P&#243;łnocna&quot; /&gt;

            &lt;Button text=&quot;Ameryka Południowa&quot;/&gt;

        &lt;/TilePane&gt;

    &lt;/top&gt;

    &lt;center&gt;
        &lt;StackPane id=&quot;Europa&quot; prefWidth=&quot;700&quot; prefHeight=&quot;650&quot; &gt;
            &lt;RadioButton text=&quot;Londyn&quot; /&gt;
            
            &lt;RadioButton text=&quot;Warszawa&quot;/&gt;
        &lt;/StackPane&gt;
    &lt;/center&gt;

    &lt;bottom&gt;

    &lt;/bottom&gt;

    &lt;right&gt;
        &lt;VBox alignment=&quot;CENTER_LEFT&quot;&gt;
            &lt;Label text=&quot;Your City :&quot;/&gt;
            &lt;Label text=&quot;Time in your City :&quot;/&gt;
        &lt;/VBox&gt;
    &lt;/right&gt;
&lt;/BorderPane&gt;

Also when I tried positioning like that it works but space over the button and on the left also activates button so I guess it is not a proper way

 &lt;center&gt;
        &lt;StackPane id=&quot;Europa&quot; alignment=&quot;TOP_LEFT&quot; prefWidth=&quot;700&quot; prefHeight=&quot;650&quot;  &gt;
            &lt;RadioButton text=&quot;Londyn&quot; &gt;
            &lt;padding&gt;&lt;Insets top=&quot;50&quot; left=&quot;50&quot;/&gt;&lt;/padding&gt;
            &lt;/RadioButton&gt;
            &lt;RadioButton text=&quot;Warszawa&quot;/&gt;
        &lt;/StackPane&gt;
    &lt;/center&gt;

答案1

得分: 0

我找到了答案。在堆叠面板中,要移动我的按钮,我必须正确操作X和Y轴。在FXML文件中,正确的做法例如:

<RadioButton text="Warszawa" translateX="500" translateY="100"/>
英文:

I've found the answer. In the Stack Pane to move my buttons i have to operate X an Y axis the proper way to do that in FXML file is for example:

&lt;RadioButton text=&quot;Warszawa&quot; translateX=&quot;500&quot; translateY=&quot;100&quot;/&gt;

huangapple
  • 本文由 发表于 2020年5月4日 16:17:44
  • 转载请务必保留本文链接:https://java.coder-hub.com/61587861.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定