I just updated to JavaFX 2.1 b19 and noticed that double click in my TreeCells doesn't work anymore.
It used to work in prior versions (last version I had was b13).
As this is quite important for us, is it possible to get fixed for 2.1 GA ?
EDIT:
After some deeper investigation, I figured out, the problem only occurs, when the TreeView is within a Tab control. My first thought, was that maybe the Tab control consumes some mouseevents, but double clicking on a TextField still works within a tab.
Here is some sample code. Double-click the TreeItem ("String1") with left mouse key. No output. Double-click it with right mouse key: output!
Put the treeview out of the tab and as a direct child of root: Double-clicking works again for both mouse keys.
If you can't fix it for 2.1, is there a workaround?
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;
public class TestApp3 extends Application {
public static void main(String[] args) {
launch(args);
}
public void start(final Stage stage) throws Exception {
VBox root = new VBox();
TreeItem<String> rootTreeItem = new TreeItem<String>();
TreeView<String> treeView = new TreeView<String>(rootTreeItem);
treeView.setRoot(rootTreeItem);
rootTreeItem.getChildren().add(new TreeItem<String>("String1"));
treeView.setShowRoot(false);
treeView.setCellFactory(new Callback<TreeView<String>, TreeCell<String>>() {
@Override
public TreeCell<String> call(TreeView<String> contactItemTreeView) {
TreeCell<String> treeCell = new TreeCell<String>() {
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
setText(item);
}
};
treeCell.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent) {
if (mouseEvent.getClickCount() == 2) {
System.out.println("Double clicked");
}
}
});
return treeCell;
}
});
TabPane tabPane = new TabPane();
Tab tab = new Tab();
tab.setText("Tab1");
tab.setContent(treeView);
tabPane.getTabs().add(tab);
root.getChildren().addAll(tabPane);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
It used to work in prior versions (last version I had was b13).
As this is quite important for us, is it possible to get fixed for 2.1 GA ?
EDIT:
After some deeper investigation, I figured out, the problem only occurs, when the TreeView is within a Tab control. My first thought, was that maybe the Tab control consumes some mouseevents, but double clicking on a TextField still works within a tab.
Here is some sample code. Double-click the TreeItem ("String1") with left mouse key. No output. Double-click it with right mouse key: output!
Put the treeview out of the tab and as a direct child of root: Double-clicking works again for both mouse keys.
If you can't fix it for 2.1, is there a workaround?
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;
public class TestApp3 extends Application {
public static void main(String[] args) {
launch(args);
}
public void start(final Stage stage) throws Exception {
VBox root = new VBox();
TreeItem<String> rootTreeItem = new TreeItem<String>();
TreeView<String> treeView = new TreeView<String>(rootTreeItem);
treeView.setRoot(rootTreeItem);
rootTreeItem.getChildren().add(new TreeItem<String>("String1"));
treeView.setShowRoot(false);
treeView.setCellFactory(new Callback<TreeView<String>, TreeCell<String>>() {
@Override
public TreeCell<String> call(TreeView<String> contactItemTreeView) {
TreeCell<String> treeCell = new TreeCell<String>() {
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
setText(item);
}
};
treeCell.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent) {
if (mouseEvent.getClickCount() == 2) {
System.out.println("Double clicked");
}
}
});
return treeCell;
}
});
TabPane tabPane = new TabPane();
Tab tab = new Tab();
tab.setText("Tab1");
tab.setContent(treeView);
tabPane.getTabs().add(tab);
root.getChildren().addAll(tabPane);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}