标签: fxmlloader

每个声明都需要@FXML吗?

每个声明都需要@FXML,还是第一个?

换句话说,我应该使用

@FXML
public Label timerLabel = new Label();
@FXML
public TextField mainTextField, projectTextField ;
@FXML
public Button goButton, deleteAllButton ;
@FXML
public ComboBox<String> projectComboBox ;
@FXML
public TableView<Entry> mainTable ;
@FXML
public TableColumn<Entry, String> titleColumn, timeColumn, dateColumn ;
@FXML
public TableColumn<Entry, Boolean> checkColumn, buttonColumn ;
@FXML
public checkBox checkAllCheckBox ;
Run Code Online (Sandbox Code Playgroud)

要么

@FXML
public Label timerLabel = new Label();
public TextField mainTextField, projectTextField ;
public Button goButton, deleteAllButton ;
public ComboBox<String> projectComboBox ;
public TableView<Entry> mainTable ;
public TableColumn<Entry, String> …
Run Code Online (Sandbox Code Playgroud)

javafx fxml fxmlloader

13
推荐指数
2
解决办法
1万
查看次数

JavaFX 8 - 每个选项卡都有单独的FXML和控制器的Tabpanes和选项卡

我希望得到一些关于在tabpane中为每个选项卡提供fx:include语句的答案.我已经轻松地管理内容以显示但是相关控制器类的引用方法只是给我一个nullpointerreference异常,无论我如何构造它.包含的FXML布局的控制器既没有构造函数也没有初始化()方法,是否需要它们?我尝试了一些不同的东西,但总是得到同样的例外.

我只是在tabpane中添加一个更改侦听器,当按下一个选项卡时,我想填充一些带有从全局可访问的arraylist获取的值的文本字段.注意:arraylist不是问题,使用主控制器执行此操作工作正常.

我将很快添加一个代码示例,但现在不能.如果您需要更多信息,请告诉我,否则我会在今天晚些时候发布代码.

*编辑,这是我的代码示例,取自StackOverflow上的另一个线程. JavaFX TabPane - 每个选项卡一个控制器

TestApp.java:

public class TestApp extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        Scene scene = new Scene(new StackPane());

        FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/MainTestWindow.fxml"));
        scene.setRoot(loader.load());
        MainTestController controller = loader.getController();
        controller.init();

        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
Run Code Online (Sandbox Code Playgroud)

主控制器,我想引用子控制器.

public class MainTestController {

    @FXML private TabPane tabPane;
    // Inject tab content.
    @FXML private Tab fooTabPage;
    // Inject controller
    @FXML private FooTabController fooTabPageController;

    // Inject tab content. …
Run Code Online (Sandbox Code Playgroud)

java model-view-controller javafx fxml fxmlloader

12
推荐指数
1
解决办法
1万
查看次数

JAVA FXCollections LoadException类不是有效类型

我正试图在本教程的帮助下用一些数据实现TableView .

我坚持将数据从我的"Person.java"填充到TableView.

我将问题跟踪到<Person firstName="Jacob" lastName="Smith" email="jacob.smith@example.com" />最底部的"fxmltableview.fxml"文件中的部分.

因此,似乎由于某种原因,我的"observableArrayList"并不是全部包含"Person.java"对象.允许"String.java".因为我在教程中逐字逐句地读了几遍,所以我没有对文件进行任务的想法,我没有看到我的文件之间有任何区别.每当我删除<Person someStuff/>它工作正常.

我怎样才能摆脱这个烦人的错误?

引发者:javafx.fxml.LoadException:Person不是有效类型./D:/workspace/TableViewExampleFXML/bin/application/fxmltableview.fxml:40

FXML-文件:

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

<?import fxmltableview.*?>

<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.cell.PropertyValueFactory?>

<?import javafx.scene.layout.GridPane?>

<?import javafx.collections.FXCollections?>


<GridPane alignment="CENTER" hgap="10.0" maxHeight="-Infinity"
    maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
    prefHeight="400.0" prefWidth="600.0" vgap="10.0" xmlns="http://javafx.com/javafx/8"
    xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.FXMLTableViewController">

    <TableView fx:id="tableView" prefHeight="200.0" prefWidth="200.0"
        GridPane.columnIndex="0" GridPane.rowIndex="1">
        <columns>
            <TableColumn prefWidth="75.0" text="First Name">
                <cellValueFactory>
                    <PropertyValueFactory property="firstName" />
                </cellValueFactory>
            </TableColumn>
            <TableColumn prefWidth="75.0" text="Last Name">
                <cellValueFactory>
                    <PropertyValueFactory property="lastName" />
                </cellValueFactory>
            </TableColumn>
            <TableColumn prefWidth="75.0" text="Email Address">
                <cellValueFactory>
                    <PropertyValueFactory …
Run Code Online (Sandbox Code Playgroud)

java javafx fxml fxmlloader

7
推荐指数
1
解决办法
9810
查看次数

JavaFX + FXML + webstart:为什么这不起作用?

让我们使用带有FXML的JavaFX 8创建最简单的Hello World应用程序:

src/application/Main.java:

package application;

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

public class Main extends Application {
    @Override
    public void start(Stage stage) {
        try {
            System.out.println("Main.start()");
            FXMLLoader fxml_loader = new FXMLLoader();
            fxml_loader.setLocation(getClass().getResource("Sample.fxml"));
            System.out.println("FXML resource URL = " + getClass().getResource("Sample.fxml"));
            Parent root = fxml_loader.load(); 
            Scene scene = new Scene(root, 300, 200);
            stage.setScene(scene);
            stage.setTitle("JFX HW");
            stage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}
Run Code Online (Sandbox Code Playgroud)

src/application/Sample.fxml:

<?xml …
Run Code Online (Sandbox Code Playgroud)

java javafx java-web-start fxmlloader

4
推荐指数
1
解决办法
1006
查看次数

在fxml中旋转图像动画

我有一个自定义图像,我只需要在加载相应页面时旋转图像,而不是默认的不确定进度指示器符号即可。我们是否有任何CSS代码可以连续旋转图像。请指导我。

css javafx fxml fxmlloader

3
推荐指数
1
解决办法
1455
查看次数

Afterburner.fx fxml load error

I try to use Afterburner.fx for DI in my project. I take followme.fx example and I try to apply to my project. But I don't know what's wrong because I follow example but when I run app, I get these exception:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$151(LauncherImpl.java:182)
    at com.sun.javafx.application.LauncherImpl$$Lambda$50/1030870354.run(Unknown …
Run Code Online (Sandbox Code Playgroud)

dependency-injection javafx fxml fxmlloader

3
推荐指数
1
解决办法
1753
查看次数

访问父控制器中加载的FXML的元素

我目前有以下情况:

我创建了一个由FXML控制器备份的FXML文件.屏幕由侧边栏和儿童托架组成.当我单击侧边栏中的元素时,我在子容器中加载了一个额外的FXML文件,如下所示:

childHolder.getChildren().addAll(FXMLLoader.load(getClass().getResource("SidebarItem1.fxml")));
Run Code Online (Sandbox Code Playgroud)

这很好用.但是我想在父控制器的控制器中访问加载的FXML的一些元素.我刚加载后,我刚刚初始化了子FXML的元素.

我已经看过这个问题:JAVAFX - FXML - 从父控制器访问加载的FXML控件,但是当我这样做时,我仍然会收到错误:

FXMLLoader loader = new FXMLLoader(getClass().getResource("SidebarItem1.fxml"));
loader.setController(this);
childHolder.getChildren().addAll(loader.load());

someChildTextField.setText("Some text");
Run Code Online (Sandbox Code Playgroud)

我给someChildTextField了一个fx:id,我把它放在初始化的顶部,如下所示:

@FXML public TextField someChildTextField;
Run Code Online (Sandbox Code Playgroud)

不过,我得到一个NullpointerException,所以我认为它仍然无法找到控件.

有谁知道如何在父控制器中访问加载的FXML的元素?

javafx fxml javafx-8 fxmlloader

3
推荐指数
1
解决办法
4487
查看次数

为什么我得到javafx.fxml.LoadException甚至fxml文件的路径都是正确的

我明白了

javafx.fxml.LoadException:

当我使用以下代码行加载和fxml文件时.

AnchorPane anchorPane =(AnchorPane)loader.load()

这是我的fxml文件,不包括import语句.

<AnchorPane prefHeight="537.0" prefWidth="374.0"     xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.buddhikajay.controller.NewTransactionDialogController">
   <children>
      <GridPane hgap="5.0" layoutX="30.0" layoutY="10.0" prefHeight="544.0" prefWidth="314.0" vgap="5.0">
    <columnConstraints>
      <ColumnConstraints hgrow="SOMETIMES" maxWidth="142.0" minWidth="10.0" prefWidth="69.0" />
      <ColumnConstraints hgrow="SOMETIMES" maxWidth="226.0" minWidth="10.0" prefWidth="225.0" />
    </columnConstraints>
    <rowConstraints>
      <RowConstraints maxHeight="70.0" minHeight="10.0" prefHeight="33.0" vgrow="SOMETIMES" />
      <RowConstraints maxHeight="105.0" minHeight="10.0" prefHeight="38.0" vgrow="SOMETIMES" />
      <RowConstraints maxHeight="156.0" minHeight="10.0" prefHeight="51.0" vgrow="SOMETIMES" />
        <RowConstraints maxHeight="154.0" minHeight="10.0" prefHeight="43.0" vgrow="SOMETIMES" />
        <RowConstraints maxHeight="160.0" minHeight="10.0" prefHeight="43.0" vgrow="SOMETIMES" />
        <RowConstraints maxHeight="161.0" minHeight="10.0" prefHeight="63.0" vgrow="SOMETIMES" />
        <RowConstraints maxHeight="301.0" minHeight="10.0" prefHeight="180.0" vgrow="SOMETIMES" />
        <RowConstraints maxHeight="231.0" …
Run Code Online (Sandbox Code Playgroud)

javafx fxml fxmlloader

3
推荐指数
1
解决办法
2万
查看次数

这个JavaFX/FXML自定义组件有什么问题?

我正在学习编写用于JavaFX 8和Scene Builder的FXML自定义组件.

我编写了下面显示的FXML文件,但是Scene Builder不会打开它,因为例外情况给我提示"打开操作失败":

java.io.IOException: javafx.fxml.LoadException: mycustomcomponent.TicoTeco is not a valid type.
/C:/Users/xxxxx/Documents/NetBeansProjects/MyCustomComponent/src/mycustomcomponent/TicoTeco.fxml:9
    at com.oracle.javafx.scenebuilder.kit.fxom.FXOMLoader.load(FXOMLoader.java:92)
    at com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.(FXOMDocument.java:80)
    at com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.(FXOMDocument.java:95)
...

为什么我得到这个例外?

这是FXML文件:

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<fx:root type="mycustomcomponent.TicoTeco" prefHeight="93.0" prefWidth="304.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <BorderPane layoutX="61.0" prefHeight="115.0" prefWidth="200.0">
         <left>
            <Button fx:id="tico" mnemonicParsing="false" text="Tico" BorderPane.alignment="CENTER" />
         </left>
         <right>
            <Button fx:id="teco" mnemonicParsing="false" text="Teco" BorderPane.alignment="CENTER" />
         </right>
      </BorderPane>
   </children>
</fx:root>
Run Code Online (Sandbox Code Playgroud)

以下是TicoTeco.java和Main.java的Java文件:

package mycustomcomponent;

import java.io.IOException;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button; …
Run Code Online (Sandbox Code Playgroud)

java javafx fxml javafx-8 fxmlloader

3
推荐指数
1
解决办法
7174
查看次数

使用 fx:include 时的自定义控制器工厂

我使用的是 JavaFX 15.0.1 版。我想通过向其中注入几个 FXML 文件来制作更复杂的场景,如下所示:

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

<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>

<AnchorPane fx:controller="MainFxmlController">
   <children>
      <VBox>
         <children>
            <fx:include fx:id="topMenu" source="top_menu.fxml" />
            <fx:include fx:id="navigation" source="navigation.fxml" />
            <fx:include fx:id="statusBar" source="status_bar.fxml" />
         </children>
      </VBox>
   </children>
</AnchorPane>
Run Code Online (Sandbox Code Playgroud)

在这里,我发现包含的 FXML 的控制器会自动加载并注入主控制器中名为 <value of fx:id>Controller 的 @FXML 注释字段(在本例中MainFxmlController)。

我的问题是:在这种情况下,我如何使用自己的控制器工厂来实例化相应的控制器类?我需要在构造函数中为控制器提供一些依赖项。

java user-interface javafx fxml fxmlloader

3
推荐指数
1
解决办法
42
查看次数