繁体   English   中英

我在显示在Eclipse,IntelliJ和Netbeans上使用JavaFX在Gluon Scene Builder中创建的GUI时遇到显示问题

[英]I am facing issues displaying GUI I created in Gluon Scene Builder using JavaFX on Eclipse, IntelliJ and Netbeans

我已经包含了我使用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%时冻结,并且在我的优胜美地mac上均无法使用任何版本。 另外,我尝试从fxml文件上加载GUI的Netbeans,出现黑屏。

非常感谢您在此问题上的帮助。

BorderPaneblendMode存在问题:设置为"SOFT_LIGHT"

<BorderPane id="login" blendMode="SOFT_LIGHT" maxHeight="-Infinity" ...
                       ^^^^^^^^^^^^^^^^^^^^^

如果删除该属性,将看到您的UI:

<BorderPane id="login" maxHeight="-Infinity" ...

我使用以下样板进行了测试:

package afester.javafx.examples.fxml;

import java.net.URL;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class FxmlViewer extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
       URL location = getClass().getResource("FxmlSample.fxml");
       BorderPane root = FXMLLoader.load(location);
       stage.setScene(new Scene(root));
       stage.show();
    }
}

在此处输入图片说明

顺便说一句, ScenicView是调试此类问题的非常有用的工具-它允许在运行时分析JavaFX场景图,甚至可以修改节点的属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM