Closed f4bsn closed 7 years ago
Hi, with "Command" do you mean mvvmFX Commands? If so, can you post the code of how you create and trigger the command?
The code to open the dialog has to be invoked on the JavaFX UI thread. Maybe due to some misconfiguration this isn't the case anymore? You can test this with Platform.isFxApplicationThread()
for example in a System.out-Message in your performAddFolder
method.
Yup, that's what I mean. Here's the code of the Command from my ViewModel class:
@Inject
private Stage stage;
private Command addFolderCommand;
public Command getAddFolderCommand() {
if (addFolderCommand == null) {
addFolderCommand = new DelegateCommand(() -> new Action() {
@Override
protected void action() throws Exception {
performAddFolder();
}
// TODO: 21.05.2017 , createAddFolderPossibleBinding() check if music is currently added
}, true);
}
return addFolderCommand;
}
private void performAddFolder() {
System.out.println(Platform.isFxApplicationThread());
File dir = new DirectoryChooser().showDialog(stage);
if (dir != null) {
searchFoldersForMP3(dir);
}
}
Platform.isFxApplicationThread()
is false so it is the JavaFX UI thread right?
In the constructor of DelegateCommand
you have the last parameter true
. This defines this command to be executed on a background thread. This is used to prevent the UI from freezing when long running tasks are executed.
To fix this you can either:
false
(or leave it out because false
is the default value)performAddFolder
invocation in the action
method of the command in a Platform.runLater
like this:protected void action() throws Exception {
Platform.runLater(() -> performAddFolder());
}
This should fix your code.
Perfect, thanks! It did!
Hi, I'm about to refactor our application to use your mvvm framework. From the MenuBar I was opening a DirectoryChooser or a FileChooser but the according dialogs just don't show up anymore. In my MenuBarViewModel I have the following function which is called via a Command from the MenuBarView:
Any idea why neither FileChooserDialog nor DirectoryChooserDialog are working?
Thanks, Fabian