- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何在 MainController 中实例化和初始化 Settings 的构造函数中使用参数“Settings”对象调用 MoviesSettingsController?我必须先在 SideMenuController 上传递设置,然后再在 MoviesSettingsController 上传递?我对此有点迷茫。你会在
之后找到我所有的文件此刻,我得到这个错误:
io.datafx.controller.flow.FlowException: io.datafx.controller.FxmlLoadException: java.lang.InstantiationException: maxiRename.controller.MoviesSettingsController
at io.datafx.controller.flow.action.FlowLink.handle(FlowLink.java:72)
at io.datafx.controller.flow.FlowHandler.handle(FlowHandler.java:231)
at io.datafx.controller.flow.FlowHandler.handle(FlowHandler.java:163)
at maxiRename.controller.SideMenuController.lambda$0(SideMenuController.java:79)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8413)
at com.jfoenix.controls.JFXListCell.lambda$updateItem$157(JFXListCell.java:295)
at com.jfoenix.controls.JFXListCell.access$lambda$9(JFXListCell.java)
at com.jfoenix.controls.JFXListCell$$Lambda$10.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3470)
at javafx.scene.Scene$ClickGenerator.access$8100(Scene.java:3398)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3766)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:380)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:294)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:416)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:415)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Caused by: io.datafx.controller.FxmlLoadException: java.lang.InstantiationException: maxiRename.controller.MoviesSettingsController
at io.datafx.controller.ViewFactory.createByController(ViewFactory.java:180)
at io.datafx.controller.flow.action.FlowLink.handle(FlowLink.java:69)
... 85 more
Caused by: java.lang.InstantiationException: maxiRename.controller.MoviesSettingsController
at java.lang.Class.newInstance(Class.java:427)
at io.datafx.controller.ViewFactory.createByController(ViewFactory.java:148)
... 86 more
Caused by: java.lang.NoSuchMethodException: maxiRename.controller.MoviesSettingsController.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
... 87 more
主应用程序.java:
public void start(Stage stage) throws Exception {
Flow flow = new Flow(MainController.class);
DefaultFlowContainer container = new DefaultFlowContainer();
flowContext = new ViewFlowContext();
flowContext.register("Stage", stage);
flow.createHandler(flowContext).start(container);
JFXDecorator decorator = new JFXDecorator(stage, container.getView());
decorator.setCustomMaximize(true);
Scene scene = new Scene(decorator, 770, 690);
scene.getStylesheets().add(MainMaxiFilm.class.getResource("/resources/css/jfoenix-main-demo.css").toExternalForm());
stage.setWidth(770);
stage.setHeight(690);
stage.setResizable(false);
stage.setScene(scene);
stage.show();
}
主 Controller .java:
@FXMLController(value = "/resources/fxml/Main.fxml", title = "Material Design Example")
public class MainController implements Initializable{
@FXMLViewFlowContext
private ViewFlowContext context;
@FXML
private StackPane root;
@FXML
private BorderPane mainBorderPane;
@FXML
private VBox mainVBoxTop;
@FXML
private JFXToolbar mainToolbarTop;
@FXML
private JFXHamburger mainHamburgerTop;
@FXML
private JFXDrawer mainDrawer;
private FlowHandler flowHandler;
private FlowHandler sideMenuFlowHandler;
public void initialize(URL url, ResourceBundle rb) {
try {
HamburgerBackArrowBasicTransition transition = new HamburgerBackArrowBasicTransition(mainHamburgerTop);
transition.setRate(-1);
mainDrawer.setOnDrawerOpening((e) -> {
transition.setRate(1);
transition.play();
});
mainDrawer.setOnDrawerClosing((e) -> {
transition.setRate(-1);
transition.play();
});
mainHamburgerTop.setOnMouseClicked((e)->{
if (mainDrawer. isShown() || mainDrawer.isShowing()) {
mainDrawer.close();
}
else
mainDrawer.open();
});
// create the inner flow and content
context = new ViewFlowContext();
// set the default controller
Flow innerFlow = new Flow(HomeController.class);
flowHandler = innerFlow.createHandler(context);
context.register("ContentFlowHandler", flowHandler);
context.register("ContentFlow", innerFlow);
mainDrawer.setContent(flowHandler.start());
context.register("ContentPane", mainDrawer.getContent().get(0));
// side controller will add links to the content flow
Flow sideMenuFlow = new Flow(SideMenuController.class);
sideMenuFlowHandler = sideMenuFlow.createHandler(context);
mainDrawer.setSidePane(sideMenuFlowHandler.start());
} catch (FlowException ex) {
Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
SideMenuController.java:
@FXMLController(value = "/resources/fxml/SideMenu.fxml", title = "Material Design Example")
public class SideMenuController {
@FXML
private StackPane root;
@FXML
private VBox listViewDrawer;
@FXML
private ImageView imageTopDrawer;
@FXML
private JFXListView<?> sideList;
@FXML
private Label home;
@FXML
private JFXListView<?> subList;
@FXML
private Label musics;
@FXML
private Label movies;
@FXML
private Label series;
@FXML
private Label help;
@FXML
private Label exit;
@FXMLViewFlowContext
private ViewFlowContext context;
@PostConstruct
public void init() throws FlowException, VetoException {
sideList.propagateMouseEventsToParent();
System.out.println(context);
FlowHandler contentFlowHandler = (FlowHandler) context.getRegisteredObject("ContentFlowHandler");
Flow contentFlow = (Flow) context.getRegisteredObject("ContentFlow");
System.out.println(subList.getItems().get(0));
bindNodeToController(home, HomeController.class, contentFlow, contentFlowHandler);
bindNodeToController(musics, MusicsSettingsController.class, contentFlow, contentFlowHandler);
bindNodeToController(movies, MoviesSettingsController.class, contentFlow, contentFlowHandler);
bindNodeToController(series, SeriesSettingsController.class, contentFlow, contentFlowHandler);
bindNodeToController(help, HelpController.class, contentFlow, contentFlowHandler);
}
private void bindNodeToController(Node node, Class<?> controllerClass, Flow flow, FlowHandler flowHandler) {
flow.withGlobalLink(node.getId(), controllerClass);
node.setOnMouseClicked((e) -> {
try {
flowHandler.handle(node.getId());
} catch (Exception e1) {
e1.printStackTrace();
}
});
}
}
和 MoviesSettingsControler.java:
@FXMLController(value = "/resources/fxml/MoviesSettings.fxml" , title = "Material Design Example")
public class MoviesSettingsController{
@FXML
private GridPane gridSettingsMovies;
@FXML
private Label labelSettingsMovies;
@FXML
private Label labelFilesNameSettingsMovies;
@FXML
private JFXButton buttonCancelMoviesSettings;
@FXML
private JFXButton buttonOKMoviesSettings;
@FXML
private GridPane gridFilesName;
@FXML
private ToggleGroup groupFilesName;
@FXML
private JFXRadioButton radioButtonFiles5;
@FXML
private JFXRadioButton radioButtonFiles6;
@FXML
private JFXRadioButton radioButtonFiles3;
@FXML
private JFXRadioButton radioButtonFiles2;
@FXML
private JFXRadioButton radioButtonFiles1;
@FXML
private JFXRadioButton radioButtonFiles4;
private Settings settings = new Settings();
public MoviesSettingsController (Settings pSettings)
{
this.settings = pSettings;
}
public Settings getSettings() {
return settings;
}
public void setSettings(Settings settings) {
this.settings = settings;
}
public void saveChange (int pRb, int pPart)
{
this.settings.setMovieName(pRb);
}
@FXML
void saveSettingsMovies(ActionEvent event) {
System.out.println(groupFilesName.getSelectedToggle());
}
我想要 Controller 中的设置对象。问题是围绕这个(我认为)(代码来自 SideMenuController.java):
@PostConstruct
public void init() throws FlowException, VetoException {
sideList.propagateMouseEventsToParent();
System.out.println(context);
FlowHandler contentFlowHandler = (FlowHandler) context.getRegisteredObject("ContentFlowHandler");
Flow contentFlow = (Flow) context.getRegisteredObject("ContentFlow");
System.out.println(subList.getItems().get(0));
bindNodeToController(home, HomeController.class, contentFlow, contentFlowHandler);
bindNodeToController(musics, MusicsSettingsController.class, contentFlow, contentFlowHandler);
bindNodeToController(movies, MoviesSettingsController.class, contentFlow, contentFlowHandler);
bindNodeToController(series, SeriesSettingsController.class, contentFlow, contentFlowHandler);
bindNodeToController(help, HelpController.class, contentFlow, contentFlowHandler);
}
private void bindNodeToController(Node node, Class<?> controllerClass, Flow flow, FlowHandler flowHandler) {
flow.withGlobalLink(node.getId(), controllerClass);
node.setOnMouseClicked((e) -> {
try {
flowHandler.handle(node.getId());
} catch (Exception e1) {
e1.printStackTrace();
}
});
}
非常感谢:)
最佳答案
好的,我找到了一些有用的东西。如果您看到更好的方法,请告诉我:)。
我在 MainController 中创建了一个这样的上下文:
ViewFlowContext context = new ViewFlowContext();
我用我想通过 Flow 对象传递给其他组件的所有参数和内容填充它。我是这样填的:
@FXML
private JFXDrawer mainDrawer;
private FlowHandler flowHandler;
private FlowHandler sideMenuFlowHandler;
context.register("ContentFlowHandler", flowHandler);
context.register("Settings", new Settings());
context.register("ContentFlow", innerFlow);
我正在使用 Flow 库。我将包含我想要的所有变量和对象的上下文传递给流:
Flow sideMenuFlow = new Flow(SideMenuController.class);
sideMenuFlowHandler = sideMenuFlow.createHandler(context);
mainDrawer.setSidePane(sideMenuFlowHandler.start());
之后进入 sideMenuController。
然后像这样从 context
中取回所有这些东西:
FlowHandler contentFlowHandler = (FlowHandler) context.getRegisteredObject("ContentFlowHandler");
Flow contentFlow = (Flow) context.getRegisteredObject("ContentFlow");
最后,在 movieSettingsController 中,我通过上下文取回值,仅此而已:)
settings = (Settings) context.getRegisteredObject("settings");
最后,不要忘记在您的 Controller 中使用注解 @PostConstruct
。示例:
@PostConstruct
public void init() {
// TODO Auto-generated method stub
settings = (Settings) context.getRegisteredObject("Settings");
}
我希望这对其他人有用。当您开始探索这个世界时,事情就没那么容易了。
关于java - 如何使用fxml文件和流库获取 Controller 中的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39773900/
我的主 UI 是在 FXML 文件中定义的,并且应该包含人员列表。一个人会显示一张图片和一些不同的只读文本行(姓名、年龄等......)该列表本身在整个运行时会不断变化。 (增删改查) 我知道可以创建
正如标题所述,构建表并将所有内容添加到表的初始化方法与 FXMLLoader 之间存在一定的冲突,FXMLLoader 应该为弹出窗口加载 FXML。 我的代码: 主要: import javafx.
我正在创建丰富的 UI 应用程序,我在 FXML 中使用 FXML,每个部分都有单独的 Controller 。我决定关注this教程并使用我的 fxml 作为组件。所以我使用类作为 Controll
你好, 我有以下问题。 是否可以创建一个主 fxml 文件并放置/包含另一个应该具有用户定义属性的 fxml 文件。 例如,我有:main.fxml 和一个fan_object.fxml 然后将 3
我正在尝试制作一个具有用于制作新项目的对话框的应用程序。我已经对其进行了编程,但想要清理文件结构,因此我将对话框及其 Controller 的 fxml 移至它们自己的包中。该对话框的文件位于名为 n
你好, 我有以下问题。 是否可以创建一个主 fxml 文件并放置/包含另一个应该具有用户定义属性的 fxml 文件。 例如,我有:main.fxml 和一个fan_object.fxml 然后将 3
我的应用程序有选项卡式 Pane ,因此为了保持 fxml 文件易于管理,我有一个包含选项卡的主 fxml 文件,以及每个其他选项卡的单独 fxml 文件。这工作正常,但由于某种原因,应用程序已停止加
如果状态为“1”,我想加载另一个 FXML 文件。但在下面的代码中,它不会从初始化加载另一个 FXML。如果我使用按钮,那么此代码可以工作,但我想在没有任何按钮的情况下执行此操作。谁能帮我提个建议吗?
我是 JavaFX 的新手,我想知道是否有办法将一个 fxml 文件放在 child.fxml 中,例如 parent.fxml。 为什么我需要这个? 想法是,我想创建独立的屏幕(小屏幕)并编写一个父
我的程序有一个主要的 FXML 文档,其中包含 TabPane .对于每个选项卡,我希望它有自己的 Controller 和 fxml 文件。当我尝试将外部 fmxl 文件包含到主 fxml 文档中时
我有一个用 fxml 编写的边框 Pane ,它的左 Pane 和中央 Pane 具有可互换的布局。 边框 fxml:
在上面的 fxml 中,我有许多使用相同源 fx:include source="MyCombo.fxml"的 fxml include 标记。可以这样做吗?这样做会影响 F
我需要创建许多不同的 FXML 文件,并且每个文件都有一致的布局。每个都有一个 AnchorPane,它将保存单独的内容。 有没有办法加载“基本”FXML 文件,然后加载第二个 FXML 文件,并将数
我正在尝试创建一个非常简单的带有黑色背景的VBox。就这样。没有其他的。我使用 FXML 来描述我的 VBox。 样本.fxml: Controller .java: package sa
我不明白为什么我总是有同样的错误: image 当我尝试在我的strcuture项目中添加库(fx java)时。 我的build.gradle: plugins { id 'java'
这就是我想要实现的目标。 /Package A/ /Package A/ApplicationController.java /Package A/Application.fxml 在我的 Appli
我有两个 FXML 文件。第一个描述了要显示的第一个 Pane ,其中包含一个选项卡 Pane 、一个菜单和一个菜单项,该菜单项应该在选项卡 Pane 中打开一个新选项卡并在其中绘制一组新节点。这是代
我想要做的是,如果调整场景(应用程序窗口)的大小,我想相应地调整窗口内内容的大小。我已经发布了到目前为止我已经完成的代码 加载器类 public class ResizingButtons exten
我使用的是 Java JDK 13 和 FontAwesomeFX 11。 我有一个 FXML 文件,其中包含一些 FontAwesomeIconViews,但是当将该文件加载到我的 Controll
我明白了 javafx.fxml.LoadException: 当我使用以下代码行加载 fxml 文件时。 AnchorPane anchorPane = (AnchorPane)loader.loa
我是一名优秀的程序员,十分优秀!