我已经成功将e(fx)clipse插件安装到eclipse和Scenebuilder 8.0中,它们很好地集成在一起。以前,我一直通过WindowBuilder插件在Swing中使用和开发GUI应用程序,这非常容易和方便,但是现在我必须使用JavaFX开发应用程序,这就是我安装SceneBuilder的原因。例如,在WindowBuilder中,当我右键单击一个按钮时,可以向其中添加一个动作,然后切换到代码并同时进行开发,该动作块是在代码中的按钮下自动创建的。但是在Scene Builder中,当我想添加一个动作并用代码对其进行编辑时,我失败了,这是它对我的外观:
以下是我在互联网上找到的示例的外观:
我看不到用于选择操作或handleButtonAction的箭头。我只想像好旧的WindowBuilder一样使用SceneBuilder,这可能吗?你能启发我,我做错了什么?
WindowBuilder
通过拖放UI元素来SceneBuilder
创建Java代码,其中创建FXML。因此,我们没有选择向其添加操作然后直接切换到code的选项。
Swing允许我们使用Java代码创建UI,这使设计人员很难更改视图。JavaFX通过将视图与代码分离,采用了一种对设计人员更友好的方法。JavaFX中的视图是一个单独的实体,可以使用CSS和FXML进行设计/更改。
James_D has said in one of his comments :
JavaFX follows more of a MVP-style architecture, where the view is basically passive and is manipulated by the presenter ("controller").
Basically, each view in JavaFX has a corresponding Controller(Java File) for it.
This controller is used for the following things :
fx:id
.The FXML is loaded using the FXMLLoader which in turn instantiates the Controller. The controller class is identified by fx:controller
in FXML.
How do you handle actions of the UI elements ?
You add the actions as methods inside your controller.
对于使用onAction为的Button创建的上述FXML handleButtonAction
,您需要在控制器内创建一个具有该名称的方法。
public void handleButtonAction(ActionEvent action) {
// Do you action
}
一些不错的读物:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句