我在文本字段(焦点打开)上有一个上下文菜单,带有2个CheckMenuItems。选择一个menuitem会隐藏上下文菜单。如何在选择项目后阻止上下文菜单隐藏(以允许更多选择)
ExampleApp中:
public class ContextMenuTest extends Application {
@Override
public void start(Stage primaryStage) {
ContextMenu contextMenu = new ContextMenu();
CheckMenuItem item1 = new CheckMenuItem("test1");
CheckMenuItem item2 = new CheckMenuItem("test2");
contextMenu.getItems().addAll(item1, item2);
TextField textfield = new TextField();
TextField textfield1 = new TextField();
textfield.focusedProperty().addListener((object, oldVal, newVal) -> {
if(newVal)
contextMenu.show(textfield, Side.TOP, 0, 0);
});
VBox root = new VBox();
root.getChildren().addAll(textfield, textfield1);
Scene scene = new Scene(root, 300, 250);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
感谢任何想法。
编辑: 我尝试了setAutoHide(false),但这没有帮助