簡體   English   中英

Eclipse中用於場景構建器中設計的UI的setfullscreen(boolean)

[英]setfullscreen(boolean) in eclipse for the UI designed in scene builder

我正在一個小型項目中創建一個Beatbox應用程序,在其中我使用JavaFX作為設計工具的UI和場景生成器。 當我在其中放置組件時,我可以看到它不是全屏顯示,但是當我將其與Eclipse IDE鏈接時。 我將舞台設置為全屏模式,但我將組件放置在最左端,但我想使其自身對齊。

primaryStage.setMaximized(true);

primaryStage.setMaximized(true);

它必須自動對齊,但不像它最左邊。

在此處輸入圖片說明

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

<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXProgressBar?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

 <VBox prefHeight="400.0" prefWidth="640.0" 
  xmlns="http://javafx.com/javafx/11.0.1" 
  xmlns:fx="http://javafx.com/fxml/1" fx:controller="box.firstcontroller">
 <children>
 <AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="-1.0" 
 prefWidth="-1.0" style="-fx-background-color: #78909C;" 
 VBox.vgrow="ALWAYS">
  <children>
        <JFXProgressBar layoutX="203.0" layoutY="333.0" />
        <ImageView fitHeight="186.0" fitWidth="164.0" layoutX="53.0" 
  layoutY="94.0" pickOnBounds="true" preserveRatio="true">
           <cursor>
              <Cursor fx:constant="S_RESIZE" />
           </cursor>
           <image>
              <Image url="@../login.png" />
           </image>
        </ImageView>
        <ImageView fitHeight="164.0" fitWidth="151.0" layoutX="410.0" 
  layoutY="101.0" pickOnBounds="true" preserveRatio="true">
           <image>
              <Image url="@../signup.png" />
           </image>
        </ImageView>
        <Label layoutX="251.0" layoutY="36.0" text="BeatBox">
           <font>
              <Font name="Tempus Sans ITC" size="41.0" />
           </font>
        </Label>
        <JFXButton fx:id="signup" buttonType="RAISED" layoutX="68.0" 
     layoutY="314.0" onAction="#signupform" prefHeight="44.0" 
     prefWidth="115.0" ripplerFill="#752f2f" style="-fx-background-color: 
     #ae2121;" text="Sign Up" textFill="#fcfcfcf2">
           <font>
              <Font name="Webdings" size="20.0" />
           </font>
        </JFXButton>
        <JFXButton fx:id="signin" layoutX="428.0" layoutY="312.0" 
      onAction="#signinform" prefHeight="17.0" prefWidth="115.0" style="- 
      fx-background-color: #ae2121;" text="Sign In" textFill="WHITE">
           <font>
              <Font size="20.0" />
           </font>
        </JFXButton>
       </children>
      </AnchorPane>
      </children>
     </VBox>

您實際上有幾個問題在繼續。 首先,您的根VBox具有AnchorPane作為其子元素,該子元素又包含各個節點。

這導致您不得不手動設置這些節點的X / Y坐標。 這是設計很差的。

相反,您應該使用JavaFX提供的各種布局窗格來為您布置節點。

這是一個非常基本的示例,類似於您的布局,並且具有完全可擴展性:

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

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<VBox alignment="TOP_CENTER" spacing="10.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1">
    <padding>
        <Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
    </padding>
    <children>
        <Label text="BeatBox">
            <font>
                <Font name="Tempus Sans ITC" size="48.0"/>
            </font>
        </Label>
        <HBox alignment="CENTER" spacing="10.0" VBox.vgrow="ALWAYS">
            <children>
                <Button mnemonicParsing="false" text="Sign Up"/>
                <ProgressBar prefWidth="200.0" progress="0.0"/>
                <Button mnemonicParsing="false" text="Sign In"/>
            </children>
        </HBox>
    </children>
</VBox>

請注意,我使用標題下方的HBox來水平排列按鈕。 無需手動設置坐標或尺寸; 讓JavaFX為您完成工作!

結果:

截圖

場景構建器層次結構:

屏幕截圖2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM