如何使用javafx创建完整的全屏应用程序

时间:2014-02-20 10:10:32

标签: javafx

我有一个全屏应用程序,但是当我在非全屏模式下打开新对话框(控制器)时,会显示Windows启动面板。如何使用javafx创建完整的全屏应用程序?

UPD start screen 现在我打开我的对话框...没有其他(skype,eclipse在屏幕上)窗口,它工作得很好。也许它在javafx中出错? Now i open my dialog

public class Main extends Application {
@Override
public void start(final Stage primaryStage) {
    Button btn = new Button();
    btn.setText("Say 'Hello World'");
    btn.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            Stage dialogStage = new Stage(StageStyle.UTILITY);
            dialogStage.initModality(Modality.APPLICATION_MODAL);
            dialogStage.setScene(new Scene(VBoxBuilder.create()
                    .children(new Text("Hi"), new Button("Ok."))
                    .alignment(Pos.CENTER).padding(new Insets(100)).build()));
            dialogStage.initOwner(primaryStage);
            dialogStage.show();

            System.out.println(dialogStage.getOwner() == primaryStage
                    .getOwner());
        }
    });

    StackPane root = new StackPane();
    root.getChildren().add(btn);

    Rectangle2D r = Screen.getPrimary().getBounds();
    Scene scene = new Scene(root, r.getWidth(), r.getHeight());

    primaryStage.setTitle("Hello World!");
    primaryStage.setScene(scene);
    primaryStage.setFullScreen(true);
    primaryStage.show();
}

public static void main(String[] args) {
    launch(args);
}

}

1 个答案:

答案 0 :(得分:1)

我是这样做的:

import javafx.application.Application;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.shape.Rectangle;
import javafx.stage.Screen;
import javafx.stage.Stage;

public class FullscreenFX extends Application {

    @Override
    public void start(Stage primaryStage) {

        StackPane root = new StackPane();
        Rectangle2D r = Screen.getPrimary().getBounds();
        Scene scene = new Scene(root, r.getWidth(), r.getHeight());

        System.out.println("x: "+r.getWidth()+" y: "+r.getHeight());

        Rectangle rect = new Rectangle(r.getWidth(), r.getHeight());
        root.getChildren().add(rect);

        // scene.setCursor(Cursor.NONE);  // Uncomment, if you don't need a cursor
        primaryStage.setScene(scene);
        primaryStage.setFullScreen(true);
        primaryStage.show();
    }

    /**
     * The main() method is ignored in correctly deployed JavaFX application.
     * main() serves only as fallback in case the application can not be
     * launched through deployment artifacts, e.g., in IDEs with limited FX
     * support. NetBeans ignores main().
     *
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
}

希望这有帮助