首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >setFullscreen in a ComboBox

setFullscreen in a ComboBox
EN

Stack Overflow用户
提问于 2019-05-06 09:57:52
回答 1查看 37关注 0票数 2

你好,我正在为一个游戏的UI编程。在这个UI中,我想要一个设置的场景。在设置中,我有一个ComboBox,其中我希望setFullscreen为true或false。实际上,我得到的错误“不能从类型中静态引用非静态方法setFullScreen(boolean)”,如何解决我的问题。我希望BorderlessWindow setFullscreenprintln能工作。

控制器类;

代码语言:javascript
复制
package Menue;

public class SettingEinstellungen {


    @FXML
    private ComboBox<String> Combobox;                                                                  
    ObservableList <String> Auswahl = 
            FXCollections.observableArrayList("Fullscree","Windowmode","Borderless Window");        


    @FXML 
    Button exit;                                                                                               
    @FXML
    public void initialize() {                                                                              



        Combobox.setValue("Fullscree");
        Combobox.setItems(Auswahl);
        Combobox.getSelectionModel().select("Fullscreen");


        Combobox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>(){       
            public void changed(ObservableValue<? extends String> observable, String alt, String new) {

            if(new != null) {
                switch(new) {

                    case "Fullscreen":  System.out.println("Vollbildgeklickt" +alt +neu);
                            break;      
                    case "Window-mode":     System.out.println("Fenster\t" +alt);
                            break;
                    case "Borderless Window":   Stage.setFullScreen(true);          
                            break;   
                    default: ;
                            break;
                }
            }

            }

        });}

    //public void changeCombo(ActionEvent  event) {

        //Stage.setFullscreen(true)(comboBox.getValue(Vollbild));

    //}

    @FXML   
    public void exit_press (ActionEvent  event) throws IOException  {                                   

        Stage window = (Stage)((Node)event.getSource()).getScene().getWindow();
        //window.setFullScreen(true);
        //window.setScene(new Scene(FXMLLoader.load(new File("menue_UI_1.fxml").toURI().toURL())));

        Parent root_3 = FXMLLoader.load(getClass().getResource("menue_UI_2.fxml"));
        Scene scene_3 = new Scene(root_3);
        window.setScene(scene_3);

        window.setTitle("Hauptmenü");
        window.show();

    }


}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-06 15:48:34

问题是,您没有引用实际阶段,这就是为什么要获得该错误的原因,您需要引用所显示的实际阶段,您可以像这样在执行过程中获得窗口,或者在启动程序时在顶部初始化它。

代码语言:javascript
复制
comboBox.getSelectionModel()
            .selectedItemProperty()
            .addListener((obs, oldVal, newVal) -> {

                if(newVal != null) {
                    System.out.println(newVal);
                    switch(newVal) {
                        case "Fullscreen":
                            System.out.println("Vollbildgeklickt" +oldVal + newVal);
                            break;
                        case "Window-mode":
                            System.out.println("Fenster\t" +newVal);
                            break;
                        case "Borderless Window":
                            Stage window = (Stage) comboBox.getScene().getWindow();
                            window.setFullScreen(true);
                            break;
                        default:
                            break;
                    }
                }

            });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56002846

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档