我是 JavaFX 新手。我有我的主要场景和次要场景;当我从第一个场景更改为第二个场景时,窗口的栏变得可见。我该如何解决这个问题?
这是我的代码
public class ProyectoTeoriaBD1 extends Application {
Stage primaryStage;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(final Stage primaryStage) {
this.primaryStage = primaryStage;
GridPane gp = new GridPane();
gp.setHgap(10);
gp.setVgap(10);
gp.setPadding(new Insets(25,25,25,25));
Scene firstScene = new Scene(gp);
Button b = new Button("Change Scene");
gp.add(b,1,1);
primaryStage.setScene(firstScene);
primaryStage.setFullScreen(true);
primaryStage.show();
b.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
GridPane gp = new GridPane();
Scene secondScene = new Scene(gp);
Text txtSecond = new Text("Second Scene");
gp.add(txtSecond, 1, 1);
primaryStage.setScene(secondScene);
primaryStage.setFullScreen(false);
primaryStage.setFullScreen(true);
}
});
}
}
完整的可运行可测试代码可能会有所帮助。还提供您的系统环境详细信息。我在下面测试了您的代码(您自己尝试一下),它可以在我的 Windows 7 64 位上使用 JavaFX 版本 2.2.0 运行。
(当您提供更多详细信息时,我将更新我的答案,最后欢迎来到 stackoverflow!)
Update:好吧,我猜你的主要阶段最初是全屏模式。在这种情况下,您需要切换全屏模式。见下文。
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBoxBuilder;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class Test extends Application {
private Stage primaryStage;
@Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
this.primaryStage.setFullScreen(true);
Button btn = new Button("Login");
btn.setOnAction(loginClienteHandler());
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("JavaFX version: " + com.sun.javafx.runtime.VersionInfo.getRuntimeVersion());
primaryStage.setScene(scene);
primaryStage.show();
}
public EventHandler loginClienteHandler() {
EventHandler evh = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
primaryStage.setScene(new Scene(VBoxBuilder.create().children(new Text("text")).build()));
primaryStage.sizeToScene();
primaryStage.setFullScreen(false);
primaryStage.setFullScreen(true);
}
};
return evh;
}
public static void main(String[] args) {
launch(args);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)