我已經問過這個問題,但它沒有回答。JavaFX與FXML全屏幕
如何通過按鈕切換到JavaFX的全屏模式? 但是該按鈕是用FXML(JavaFX Scene Builder)創建的。 (找不到符號(舞臺)) 如果按鈕是手動創建的,那麼它就可以工作。
public class Buch extends Application implements Initializable
{
@ Override
public void start (Stage primaryStage) throws IOException
{
Stage stage = primaryStage;
Parent root = FXMLLoader.load (getClass() getResource ("Buch.fxml").);
Scene scene = new Scene (root);
stage.setTitle ("Buch");
stage.setScene (scene);
stage.getIcons() add (new Image ("Icon.png"));
// stage.setFullScreen (true)// Works
stage.show();
}
@ FXML
public void fullscreen (ActionEvent event)
{
// stage.setFullScreen (true)// Does not work
// cannot find symbol (stage)
}
作品:
public class Buch extends Application implements Initializable
{
@ Override
public void start (Stage primaryStage) throws IOException
{
Stage stage = primaryStage;
Parent root = FXMLLoader.load (getClass() getResource ("Buch.fxml").);
Scene scene = new Scene (root);
stage.setTitle ("Buch");
stage.setScene (scene);
stage.getIcons() add (new Image ("Icon.png"));
stage.show();
btn.setOnAction (new EventHandler <ActionEvent>()
{
public void handle (ActionEvent evt)
{
stage.setFullScreen (true);
}
});
}
不(當然?)工作:
public class Buch extends Application implements Initializable
{
@ Override
public void start (Stage primaryStage) throws IOException
{
Stage stage = primaryStage;
Parent root = FXMLLoader.load (getClass() getResource ("Buch.fxml").);
Scene scene = new Scene (root);
stage.setTitle ("Buch");
stage.setScene (scene);
stage.getIcons() add (new Image ("Icon.png"));
stage.show();
*/
@ FXML
public void fullscreen (ActionEvent event)
{
stage.setFullScreen (true)// Does not work
// cannot find symbol (stage)
}
/*// Will not work
}
您也可以看看這個鏈接。現在的問題是更詳細的在這裏:
stackoverflow.com/questions/22820049/full-screen-under-javafx-with-fxml-does-not-work
我如何使用級可變哪兒了嗎?還是有另一種解決方案? 請幫幫我。
在互聯網上沒有回答我的問題!?!
我是一個Java初學者。 :-)
感謝您的幫助
非常感謝James_D。 這是正確的解決方案: Stage stage =(Stage)fullScreenButton.getScene()getWindow(); 你也贏得了「投票」的觀點,但我需要15個聲望點才能做到這一點:-(如果我有15分,我也會這麼做。:-) – user3487276