我已经包含了我使用Gluon Scene构建器创建的sample.fxml。 我面临的问题是,每当我作为Java FX项目运行时,我只会得到一个空白屏幕。
<?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.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.effect.Glow?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>
<BorderPane id="login" blendMode="SOFT_LIGHT" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: gray;" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<left>
<Pane prefHeight="299.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<children>
<Label id="username_label" alignment="CENTER" contentDisplay="CENTER" layoutX="72.0" layoutY="57.0" prefHeight="35.0" prefWidth="100.0" style="-fx-background-color: wheat; -fx-border-color: brown;" text="username">
<font>
<Font name="Wawati SC Regular" size="16.0" />
</font>
<padding>
<Insets bottom="5.0" left="15.0" right="8.0" top="5.0" />
</padding>
</Label>
<Label id="password_label" alignment="CENTER" contentDisplay="CENTER" layoutX="72.0" layoutY="141.0" prefHeight="35.0" prefWidth="100.0" style="-fx-background-color: wheat; -fx-border-color: brown;" text="password" textAlignment="CENTER">
<font>
<Font name="Wawati SC Regular" size="16.0" />
</font>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Label>
</children>
</Pane>
</left>
<center>
<Pane prefHeight="316.0" prefWidth="371.0" BorderPane.alignment="CENTER">
<children>
<TextField id="username_tField" alignment="CENTER" layoutX="14.0" layoutY="59.0" prefHeight="30.0" prefWidth="230.0" promptText="Enter username here" style="-fx-background-color: gray;">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<font>
<Font name="Courier Oblique" size="14.0" />
</font>
<effect>
<Glow />
</effect>
</TextField>
<PasswordField id="password_tField" alignment="CENTER" layoutX="14.0" layoutY="143.0" prefHeight="30.0" prefWidth="230.0" promptText="Enter password here" style="-fx-background-color: gray;">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<font>
<Font name="Courier Oblique" size="14.0" />
</font>
<effect>
<Glow />
</effect>
</PasswordField>
<Pane layoutX="62.0" layoutY="216.0" prefHeight="57.0" prefWidth="182.0" style="-fx-background-color: gray;">
<children>
<Button id="login_Button" alignment="CENTER" contentDisplay="RIGHT" layoutX="75.0" layoutY="11.0" mnemonicParsing="false" prefHeight="35.0" prefWidth="95.0" style="-fx-background-color: wheat; -fx-border-color: brown;" text="Login" textAlignment="CENTER">
<font>
<Font name="Wawati SC Regular" size="16.0" />
</font>
<opaqueInsets>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</opaqueInsets>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Button>
</children>
</Pane>
</children>
</Pane>
</center>
<top>
<Pane id="login_title" prefHeight="84.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<children>
<Label id="login_title" alignment="CENTER" contentDisplay="CENTER" layoutX="114.0" layoutY="28.0" prefHeight="46.0" prefWidth="341.0" style="-fx-background-color: gray;" text="Welcome to Real Estate World ...">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<font>
<Font name="Wawati SC Regular" size="24.0" />
</font>
<opaqueInsets>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</opaqueInsets>
</Label>
</children>
</Pane>
</top>
</BorderPane>
当我尝试安装e(fx)eclipse时,eclipse在加载19%时冻结,并且没有任何版本在我的yosemite mac上运行。另外,Netbeans我试图从上面的fxml文件加载GUI,我得到一个空白的屏幕。
非常感谢这个问题的帮助。
答案 0 :(得分:0)
BorderPane
的{{1}}存在问题:它设置为blendMode
。
"SOFT_LIGHT"
如果删除该属性,您将看到您的用户界面:
<BorderPane id="login" blendMode="SOFT_LIGHT" maxHeight="-Infinity" ...
^^^^^^^^^^^^^^^^^^^^^
我使用以下样板来测试它:
<BorderPane id="login" maxHeight="-Infinity" ...
BTW,调试此类问题的一个非常有用的工具是ScenicView - 它允许在运行时分析JavaFX场景图,甚至修改节点的属性。