簡體   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