猿问

日食中的设置全屏(布尔值),用于在场景构建器中设计的 UI

我正在开发一个小型项目,以创建一个 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: 


qq_遁去的一_1
浏览 158回答 1
1回答

慕的地8271018

你实际上有几个问题正在发生。首先,您的根有一个 as 的子元素,它又包含各个节点。VBoxAnchorPane这会导致您被迫手动设置这些节点的 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">&nbsp; &nbsp; <padding>&nbsp; &nbsp; &nbsp; &nbsp; <Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>&nbsp; &nbsp; </padding>&nbsp; &nbsp; <children>&nbsp; &nbsp; &nbsp; &nbsp; <Label text="BeatBox">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <font>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Font name="Tempus Sans ITC" size="48.0"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </font>&nbsp; &nbsp; &nbsp; &nbsp; </Label>&nbsp; &nbsp; &nbsp; &nbsp; <HBox alignment="CENTER" spacing="10.0" VBox.vgrow="ALWAYS">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <children>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Button mnemonicParsing="false" text="Sign Up"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ProgressBar prefWidth="200.0" progress="0.0"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Button mnemonicParsing="false" text="Sign In"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </children>&nbsp; &nbsp; &nbsp; &nbsp; </HBox>&nbsp; &nbsp; </children></VBox>请注意,我使用标题下方的 来水平布局按钮。无需手动设置坐标或尺寸;让爪哇FX为您完成工作!HBoxThe Result:Scene Builder Heirarchy:
随时随地看视频慕课网APP

相关分类

Java
我要回答