【问题标题】:Loading FXML from a pastebin从 pastebin 加载 FXML
【发布时间】:2014-08-23 18:26:07
【问题描述】:

我正在开发一个需要从以下 URL 加载 fxml 源的 JavaFX 程序:http://pastebin.com/raw.php?i=SW5d5ucs

<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="201.0" prefWidth="299.0" style="-fx-background-color: #2B2B2B;" fx:controller="aio_pkhonor.core.ui.crafting.CraftingInterfaceController" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label alignment="CENTER" layoutX="6.0" layoutY="6.0" prefHeight="51.0" prefWidth="291.0" text="Gem Crafting" textFill="WHITE">
<font>
<Font name="Rod" size="28.0"/>
</font>
</Label>
<Button fx:id="StartButton" layoutX="15.0" layoutY="162.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="273.0" style="-fx-background-color: #1b1b1b;" text="Start Script" textFill="WHITE"/>
<Label layoutX="28.0" layoutY="120.0" text="Gem To Craft : " textFill="WHITE"/>
<ComboBox fx:id="GemComboBox" layoutX="108.0" layoutY="116.0" prefHeight="25.0" prefWidth="163.0" promptText="Select Gem"/>
<RadioButton fx:id="AutoTrainButton" layoutX="24.5439453125" layoutY="57.0" mnemonicParsing="false" text="AutoTrain (Trains Your Acc To 2Bil XP)" textFill="WHITE">
<toggleGroup>
<ToggleGroup fx:id="group"/>
</toggleGroup>
</RadioButton>
<RadioButton fx:id="CustomTrainButton" layoutX="25.0" layoutY="84.0" mnemonicParsing="false" text="Custom" textFill="WHITE" toggleGroup="$group"/>
</children>
</AnchorPane>

我尝试了一些东西,但似乎无法弄清楚,如果有人能帮助我,那就太好了。

【问题讨论】:

  • 您的意思是要加载那里显示的 FXML,还是您的字面意思是要在运行时从该位置下载 FXML?无论哪种方式,您能否展示您尝试过的代码并解释您尝试时出现的问题?
  • 我试过使用 DOM 解析器,我不介意它是如何加载的,只要我可以使用 fxml 来显示我的 JavaFX 应用程序。

标签: javafx fxml fxmlloader


【解决方案1】:

假设你的类路径上有控制器,你可以这样做

import java.net.URL;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class RemoteFXMLTest extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        Parent root = FXMLLoader.load(new URL("http://pastebin.com/raw.php?i=SW5d5ucs"));
        Scene scene = new Scene(root, 600, 400);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

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

或者你可以复制代码,将其保存为 FXML 文件,然后以标准方式使用它...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-16
    • 2019-02-22
    • 2013-07-22
    • 1970-01-01
    • 1970-01-01
    • 2017-02-08
    • 1970-01-01
    相关资源
    最近更新 更多