【发布时间】:2014-04-04 10:27:53
【问题描述】:
我已经问过这个问题,但没有得到回答。
如何在 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 初学者。 :-)
感谢您的帮助
【问题讨论】: