Java Applet不显示FXML格式

时间:2018-06-23 22:15:14

标签: java javafx japplet

我有一个Java小程序:

public abstract class FXApplet extends JApplet {

    /**
     * Initializes a Swing thread
     */
    @Override
    public void init() {
        SwingUtilities.invokeLater(this::initSwing);
    }

    /**
     * Initializes a JavaFX thread
     */
    private void initSwing() {
        JFXPanel panel = new JFXPanel();
        add(panel);

        Platform.runLater(() -> initFX(panel));
    }

    /**
     * Here u can use JavaFX components
     * @param panel Root panel
     */
    abstract protected void initFX(JFXPanel panel);
}

public class FSSApplet extends FXApplet {

    @Override
    protected void initFX(JFXPanel panel) {

        try {
            ClassLoader classLoader = getClass().getClassLoader();
            URL res = classLoader.getResource("views/fss.fxml");
            Parent root = FXMLLoader.load(res);
            Scene scene = new Scene(root);
            panel.setScene(scene);
        } catch (IOException e) {
            e.printStackTrace();
            Alert alert = new Alert(Alert.AlertType.ERROR);
            alert.setTitle("Ошибка");
            alert.setHeaderText("Критическая ошибка");
            alert.setContentText("Неудалось загрузить форму");

            alert.showAndWait();
        }
    }
}

但是当我在浏览器中运行小程序时,它仅显示一个灰色框。但是,如果我使用Swing组件,浏览器将完美显示所有内容。 我的FXML表单:

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

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>

<GridPane maxHeight="-Infinity" maxWidth="-Infinity"
          minHeight="-Infinity" minWidth="-Infinity"
          prefHeight="400.0" prefWidth="600.0"
          fx:controller="com.contedevel.fss.controller.FSSController"
          xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1">
  <columnConstraints>
    <ColumnConstraints hgrow="NEVER" minWidth="200.0" prefWidth="200.0" />
    <ColumnConstraints hgrow="ALWAYS" minWidth="10.0" prefWidth="100.0" />
  </columnConstraints>
  <rowConstraints>
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
  </rowConstraints>
   <children>
      <VBox prefHeight="200.0" prefWidth="100.0">
         <children>
            <Label text="Label" fx:id="txtResult"/>
            <Button mnemonicParsing="false" onAction="#handleFindAction" text="Find" />
         </children>
      </VBox>
   </children>
</GridPane>

HTML:

<div class="page">
    <applet code="com.contedevel.fss.applet.FSSApplet.class" width="100%" height="100%">Загрузка аплета</applet>
</div>

简而言之,JavaFX无法正常工作,也不会显示任何错误。问题出在哪里?

PS 。我使用Java 8和旧的Firefox浏览器。它支持小程序。

0 个答案:

没有答案