[当我创建一个新的IntelliJ IDEA项目时,我创建了简单的FXML。
我的项目结构仅包括此FXML,ControllerClass,PresenterClass和Main类。我正在使用Gradle 4.3.1。没有导入标记为红色,我可以启动程序。
我试图在Scenebuilder中打开FXML(我之前尝试在IDE的Frame中打开FXML,正确设置了“通往Scenebuilder的路径”),但它也没有起作用。当我尝试在Scenebuilder中打开FXML时,引发了以下错误:
java.lang.IllegalArgumentException: EventType "LIFECYCLE_EVENT"with parent "EVENT" already exists
java.lang.ExceptionInInitializerError
我将提供代表:
Main.java
package mats.app.fxml;
import com.gluonhq.charm.glisten.application.MobileApplication;
import com.gluonhq.charm.glisten.visual.Swatch;
import javafx.scene.Scene;
import mats.app.fxml.views.TestView;
public class Main extends MobileApplication {
public static final String TESTSCENE = HOME_VIEW;
@Override
public void init() {
addViewFactory(TESTSCENE, () -> new TestView().getView());
}
@Override
public void postInit(Scene scene) {
Swatch.BLUE.assignTo(scene);
}
}
Testview.java
package mats.app.fxml.views;
import com.gluonhq.charm.glisten.mvc.View;
import java.io.IOException;
import javafx.fxml.FXMLLoader;
public class TestView {
public View getView() {
try {
return FXMLLoader.load(Scene2View.class.getResource("test.fxml"));
} catch (IOException e) {
System.out.println("IOException: " + e);
return new View();
}
}
}
TestPresenter.java
package mats.app.fxml.views;
import com.gluonhq.charm.glisten.application.MobileApplication;
import com.gluonhq.charm.glisten.control.AppBar;
import com.gluonhq.charm.glisten.mvc.View;
import com.gluonhq.charm.glisten.visual.MaterialDesignIcon;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import java.net.URL;
import java.util.ResourceBundle;
public class TestPresenter {
@FXML
Button button1;
@FXML
Label label;
public void button1Click(ActionEvent actionEvent) {
label.setText("Button1 clicked");
button1.setText("Click me again!");
}
}
test.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import com.gluonhq.charm.glisten.mvc.View?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>
<View xmlns:fx="http://javafx.com/fxml/1" fx:controller="mats.app.fxml.views.TestPresenter">
<VBox alignment="CENTER" spacing="15">
<Label text="Label" fx:id="label"/>
<Button text="Button" fx:id="button1" onAction="#button1Click"/>
</VBox>
</View>
问候MatsG23
如果使用IntelliJ的嵌入式Scene Builder,则不包括Gluon Mobile控件。如果您使用独立应用程序Scene Builder,则应该能够使用Gluon View组件打开FXML文件。