javafx - 在组合框中设置全屏
问题描述
您好,我正在为游戏编写 UI。在这个 UI 中,我想要一个带有设置的场景。在设置中,我有一个ComboBox
我想要setFullscreen
的真假。实际上,我收到错误“无法setFullScreen(boolean)
从类型中对非静态方法进行静态引用”如何解决我的问题。我希望 BorderlessWindow setFullscreen
真正的println
工作。
控制器类;
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();
}
}
解决方案
问题是你没有引用实际阶段,这就是为什么你得到那个错误你需要引用显示的实际阶段你可以通过在执行期间获取窗口来做到这一点,或者你可以在顶部初始化它你启动程序
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;
}
}
});
推荐阅读
- c# - Run 组件上的 WPF StringFormat 使用错误的区域性
- java - 使用 JOption 窗格的 If 和 Else 语句
- jquery - 406 不接受 JQuery + Spring 5 Rest
- git - Gitlab - SSH KEY怀疑
- android - 如何避免重定向到已评价应用的商店用户?
- pyspark - 从 Databricks Notebook 连接到 Azure SQL 数据库
- google-chrome - Chrome Selenium IDE 随机数生成器
- kubernetes - Kubernetes入口nginx不匹配子路径
- count - 我找不到构建单个查询以获取不同值出现次数的方法
- php - 我可以更改电子邮件通知新用户 Wordpress