Skip to main content
 首页 » 编程设计

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

2024年11月24日85xing901022

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

更新 start screen 现在我打开我的对话框...在没有其他(Skype、屏幕中的 Eclipse)窗口的情况下,它工作得很好。也许是javafx中的bug? 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); 
} 

}

请您参考如下方法:

我是这样做的:

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); 
    } 
} 

希望这有帮助