相关疑难解决方法(0)

在模型类中使用javafx.beans属性

在模型类中使用JavaFX bean属性是否正确?

我想知道在模型类中使用属​​性是否能够更容易地使用视图组件绑定它们是一个好习惯.我不担心将来这些库的可用性,因为我的程序将在JRE8或更高版本上运行,但在模型类中使用JavaFX库的性质让我持怀疑态度,我担心当前和未来的不兼容性,特别是因为我想使用Hibernate来持久保存这些属性.

注意:我使用纯JavaFX环境,在我的应用程序中永远不需要Swing兼容性.

java persistence hibernate model javafx

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

SimpleStringProperty和StringProperty之间的区别

我正在使用JavaFx TableView,发现有一些类使用TableView,例如SimpleStringProperty,StringProperty,SimpleBooleanProperty和BooleanProperty等.现在我想知道哪一个用于TableView的SimpleStringProperty或者只有StringProperty和它们之间有什么区别?他们.

java javafx javabeans

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

JavaFX:使用常量字符串前缀绑定StringProperty

我对JavaFX中的绑定功能有疑问.我想要的是绑定2个字符串属性.但他们的价值观不应该相等.

让我举一个例子:

我有一个StringProperty代表我的应用程序中最后打开的项目.
值类似于"C:\ temp\myProject.prj".
我想在窗口标题中显示此路径.
这很简单:stage.titleProperty().bind(lastprojectProperty());
但我不想只显示项目路径,还要显示应用程序名称,
例如:MyApplication 2.2.4 - C:\ temp\myProject.prj.

可以使用绑定并添加一个常量前缀字符串吗?或者我是否使用ChangeListerner?

使用ChangeListener的解决方案存在初始值的问题......

    final StringProperty path = new SimpleStringProperty("untitled");
    final StringProperty title = new SimpleStringProperty("App 2.0.0");

    path.addListener(new ChangeListener<String>()
  {
        @Override
        public void changed(ObservableValue<? extends String> ov, String t, String newValue)   
        {
            title.setValue("App 2.0.0 - " + newValue);
        }
  });                

    // My title shows "App 2.0.0" since there is now change event throws until now...
    // Of course I could call path.setValue("untitled"); 
    // And above path = new …
Run Code Online (Sandbox Code Playgroud)

bind javafx properties changelistener

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

JavaFX从FXML子访问父控制器类

使用JavaFX作为应用程序,我有一个Main.fxml文件,里面有一些fxml子文件.

我想从子控制器访问Main.fxml的MainController类.

我将尝试用一个例子更好地解释:

MainFxml:

    <HBox fx:controller="MainController.java">
        <fx:include source="child.fxml"/>
    </HBox>
Run Code Online (Sandbox Code Playgroud)

MainController:

    public class MainController implements Initializable {
            private String string;
            public void setString (String string) {
                    this.string = string;
            }
Run Code Online (Sandbox Code Playgroud)

ChildFxml:

    <HBox fx:id="child" fx:controller="ChildController.java">
        <Button text="hello" onAction="#selectButton"></Button>
    </HBox>
Run Code Online (Sandbox Code Playgroud)

ChildController:

    public class ChildController implements Initializable {
            @FXML HBox child;
            @FXML Button button;
            @FXML
            public void selectButton (ActionEvent event) {
                // here call MainController.setString("hello");
            }
Run Code Online (Sandbox Code Playgroud)

我尝试在StackOverflow上找到这个解决方案,但我需要获取已经加载的Main.fxml的Controller引用.是否有任何方法可以从特定的窗格启动Controller?就像是:

    // child.getParent().getController();
Run Code Online (Sandbox Code Playgroud)

java javafx fxml

6
推荐指数
1
解决办法
4640
查看次数