在 ComboBox 中设置全屏
setFullscreen in a ComboBox
您好,我正在为游戏编写 UI。在此 UI 中,我想要一个带有设置的场景。在设置中,我有一个 ComboBox
,我希望 setFullscreen
为 true 或 false。实际上我收到错误 "Cannot make a static reference to the non-static method setFullScreen(boolean)
from the type " 我该如何解决我的问题。我希望 BorderlessWindow setFullscreen
true println
正常工作。
控制器 CLASS;
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();
}
}
问题是您没有引用实际阶段,这就是为什么您会收到该错误,您需要引用显示的实际阶段,您可以通过在执行过程中获取 window 来做到这一点或者你可以在启动程序时在顶部初始化它
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;
}
}
});
您好,我正在为游戏编写 UI。在此 UI 中,我想要一个带有设置的场景。在设置中,我有一个 ComboBox
,我希望 setFullscreen
为 true 或 false。实际上我收到错误 "Cannot make a static reference to the non-static method setFullScreen(boolean)
from the type " 我该如何解决我的问题。我希望 BorderlessWindow setFullscreen
true println
正常工作。
控制器 CLASS;
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();
}
}
问题是您没有引用实际阶段,这就是为什么您会收到该错误,您需要引用显示的实际阶段,您可以通过在执行过程中获取 window 来做到这一点或者你可以在启动程序时在顶部初始化它
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;
}
}
});