Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不带自动隐藏的JavaFX MenuItem_Java_User Interface_Javafx_Javafx 8 - Fatal编程技术网

不带自动隐藏的JavaFX MenuItem

不带自动隐藏的JavaFX MenuItem,java,user-interface,javafx,javafx-8,Java,User Interface,Javafx,Javafx 8,我想要一个菜单项(更具体的是CheckMenuItem),它不会在单击时自动隐藏。我知道CustomMenuItem具有此功能,但它应该是一个CheckMenuItem。在构造函数中使用,和一个复选框 编辑: 我刚刚注意到JavaFX8U40中的内容很混乱。菜单项文本颜色与背景颜色相同,因此您看不到任何文本 一个快速的解决方法是设置文本样式,例如。g cb.setStyle("-fx-text-fill: -fx-text-base-color"); 下面是一个完整的示例: public c

我想要一个菜单项(更具体的是CheckMenuItem),它不会在单击时自动隐藏。我知道CustomMenuItem具有此功能,但它应该是一个CheckMenuItem。

在构造函数中使用,和一个复选框


编辑:

我刚刚注意到JavaFX8U40中的内容很混乱。菜单项文本颜色与背景颜色相同,因此您看不到任何文本

一个快速的解决方法是设置文本样式,例如。g

cb.setStyle("-fx-text-fill: -fx-text-base-color");
下面是一个完整的示例:

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {

            VBox root = new VBox();

             MenuBar menuBar = new MenuBar();

            final Menu menu = new Menu( "Items");

            for( int i=0; i < 10; i++) {

                CheckBox cb = new CheckBox( "Item " + i);

                // workaround: the color of the labels is wrong (white text on white background), we have to set it explicitly
                cb.setStyle("-fx-text-fill: -fx-text-base-color");

                CustomMenuItem cmi = new CustomMenuItem( cb);
                cmi.setHideOnClick(false);

                menu.getItems().add( cmi);

            }

            menu.getItems().add( new MenuItem( "This one doesn't stay open"));

            menuBar.getMenus().add( menu);


            root.getChildren().add( menuBar);

            Scene scene = new Scene(root,400,400);

            primaryStage.setScene(scene);
            primaryStage.show();

        } catch(Exception e) {
            e.printStackTrace();
        }


    }

    public static void main(String[] args) {
        launch(args);
    }
}
public类主扩展应用程序{
@凌驾
公共无效开始(阶段primaryStage){
试一试{
VBox root=新的VBox();
菜单栏菜单栏=新建菜单栏();
最终菜单=新菜单(“项目”);
对于(int i=0;i<10;i++){
复选框cb=新复选框(“项目”+i);
//解决方法:标签的颜色错误(白色背景上的白色文本),我们必须明确设置它
cb.setStyle(“-fx文本填充:-fx文本基色”);
CustomMenuItem cmi=新CustomMenuItem(cb);
cmi.setHideOnClick(false);
menu.getItems().add(cmi);
}
menu.getItems().add(新菜单项(“此菜单项未保持打开”);
menuBar.getMenus().add(菜单);
root.getChildren().add(菜单栏);
场景=新场景(根,400400);
初级阶段。场景(场景);
primaryStage.show();
}捕获(例外e){
e、 printStackTrace();
}
}
公共静态void main(字符串[]args){
发射(args);
}
}
在构造函数中使用、和复选框


编辑:

我刚刚注意到JavaFX8U40中的内容很混乱。菜单项文本颜色与背景颜色相同,因此您看不到任何文本

一个快速的解决方法是设置文本样式,例如。g

cb.setStyle("-fx-text-fill: -fx-text-base-color");
下面是一个完整的示例:

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {

            VBox root = new VBox();

             MenuBar menuBar = new MenuBar();

            final Menu menu = new Menu( "Items");

            for( int i=0; i < 10; i++) {

                CheckBox cb = new CheckBox( "Item " + i);

                // workaround: the color of the labels is wrong (white text on white background), we have to set it explicitly
                cb.setStyle("-fx-text-fill: -fx-text-base-color");

                CustomMenuItem cmi = new CustomMenuItem( cb);
                cmi.setHideOnClick(false);

                menu.getItems().add( cmi);

            }

            menu.getItems().add( new MenuItem( "This one doesn't stay open"));

            menuBar.getMenus().add( menu);


            root.getChildren().add( menuBar);

            Scene scene = new Scene(root,400,400);

            primaryStage.setScene(scene);
            primaryStage.show();

        } catch(Exception e) {
            e.printStackTrace();
        }


    }

    public static void main(String[] args) {
        launch(args);
    }
}
public类主扩展应用程序{
@凌驾
公共无效开始(阶段primaryStage){
试一试{
VBox root=新的VBox();
菜单栏菜单栏=新建菜单栏();
最终菜单=新菜单(“项目”);
对于(int i=0;i<10;i++){
复选框cb=新复选框(“项目”+i);
//解决方法:标签的颜色错误(白色背景上的白色文本),我们必须明确设置它
cb.setStyle(“-fx文本填充:-fx文本基色”);
CustomMenuItem cmi=新CustomMenuItem(cb);
cmi.setHideOnClick(false);
menu.getItems().add(cmi);
}
menu.getItems().add(新菜单项(“此菜单项未保持打开”);
menuBar.getMenus().add(菜单);
root.getChildren().add(菜单栏);
场景=新场景(根,400400);
初级阶段。场景(场景);
primaryStage.show();
}捕获(例外e){
e、 printStackTrace();
}
}
公共静态void main(字符串[]args){
发射(args);
}
}
在构造函数中使用、和复选框


编辑:

我刚刚注意到JavaFX8U40中的内容很混乱。菜单项文本颜色与背景颜色相同,因此您看不到任何文本

一个快速的解决方法是设置文本样式,例如。g

cb.setStyle("-fx-text-fill: -fx-text-base-color");
下面是一个完整的示例:

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {

            VBox root = new VBox();

             MenuBar menuBar = new MenuBar();

            final Menu menu = new Menu( "Items");

            for( int i=0; i < 10; i++) {

                CheckBox cb = new CheckBox( "Item " + i);

                // workaround: the color of the labels is wrong (white text on white background), we have to set it explicitly
                cb.setStyle("-fx-text-fill: -fx-text-base-color");

                CustomMenuItem cmi = new CustomMenuItem( cb);
                cmi.setHideOnClick(false);

                menu.getItems().add( cmi);

            }

            menu.getItems().add( new MenuItem( "This one doesn't stay open"));

            menuBar.getMenus().add( menu);


            root.getChildren().add( menuBar);

            Scene scene = new Scene(root,400,400);

            primaryStage.setScene(scene);
            primaryStage.show();

        } catch(Exception e) {
            e.printStackTrace();
        }


    }

    public static void main(String[] args) {
        launch(args);
    }
}
public类主扩展应用程序{
@凌驾
公共无效开始(阶段primaryStage){
试一试{
VBox root=新的VBox();
菜单栏菜单栏=新建菜单栏();
最终菜单=新菜单(“项目”);
对于(int i=0;i<10;i++){
复选框cb=新复选框(“项目”+i);
//解决方法:标签的颜色错误(白色背景上的白色文本),我们必须明确设置它
cb.setStyle(“-fx文本填充:-fx文本基色”);
CustomMenuItem cmi=新CustomMenuItem(cb);
cmi.setHideOnClick(false);
menu.getItems().add(cmi);
}
menu.getItems().add(新菜单项(“此菜单项未保持打开”);
menuBar.getMenus().add(菜单);
root.getChildren().add(菜单栏);
场景=新场景(根,400400);
初级阶段。场景(场景);
primaryStage.show();
}捕获(例外e){
e、 printStackTrace();
}
}
公共静态void main(字符串[]args){
发射(args);
}
}
在构造函数中使用、和复选框


编辑:

我刚刚注意到JavaFX8U40中的内容很混乱。菜单项文本颜色与背景颜色相同,因此您看不到任何文本

一个快速的解决方法是设置文本样式,例如。g

cb.setStyle("-fx-text-fill: -fx-text-base-color");
下面是一个完整的示例:

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {

            VBox root = new VBox();

             MenuBar menuBar = new MenuBar();

            final Menu menu = new Menu( "Items");

            for( int i=0; i < 10; i++) {

                CheckBox cb = new CheckBox( "Item " + i);

                // workaround: the color of the labels is wrong (white text on white background), we have to set it explicitly
                cb.setStyle("-fx-text-fill: -fx-text-base-color");

                CustomMenuItem cmi = new CustomMenuItem( cb);
                cmi.setHideOnClick(false);

                menu.getItems().add( cmi);

            }

            menu.getItems().add( new MenuItem( "This one doesn't stay open"));

            menuBar.getMenus().add( menu);


            root.getChildren().add( menuBar);

            Scene scene = new Scene(root,400,400);

            primaryStage.setScene(scene);
            primaryStage.show();

        } catch(Exception e) {
            e.printStackTrace();
        }


    }

    public static void main(String[] args) {
        launch(args);
    }
}
public类主扩展应用程序{
@凌驾
公共无效开始(阶段primaryStage){
试一试{
VBox root=新的VBox();
菜单栏菜单栏=新建菜单栏();
最终菜单=新菜单(“项目”);
对于(int i=0;i<10;i++){
复选框cb=新复选框(“项目”+i);
//解决方法:标签的颜色错误(白色背景上的白色文本),我们必须明确设置它
cb.setStyle(“-fx文本填充:-fx文本基色”);
CustomMenuItem cmi=新CustomMenuItem(cb);
cmi.setHideOnClick(false);
menu.getItems().add(cmi);
}
menu.getItems().add(新菜单项(“此菜单项未保持打开”);
menuBar.getMenus().add(菜单);
root.getChildren().add(菜单栏);
场景=新场景(根,400400);
初级阶段。场景(场景);
primaryStage.show();
}捕获(例外e){
e、 printStackTr