亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

第二個屏幕上的javafx全屏

第二個屏幕上的javafx全屏

慕村9548890 2021-09-12 19:54:16
對于我的生活,我似乎無法得到這方面的幫助。我有一個 JavaFX 屏幕,我想在我的第二臺顯示器上全屏顯示。我根據其他建議嘗試了以下方法,但無濟于事。我知道坐標是正確的,但它在我的主顯示器上保持全屏顯示。請幫忙。if (mainSet.getBoolean("fullScr", false)) {  int count = mainSet.getInt("MonSel", 0);  if (count > 0) {    int i = 0;    for (Screen screen: Screen.getScreens()) {      if (count == i) {        Rectangle2D bounds = screen.getBounds();        primaryStage.setX(bounds.getMinX());        System.out.println(bounds.getMinX());        System.out.println(bounds.getMinY());        primaryStage.setY(bounds.getMinY());      }      i++;    }  }  primaryStage.setFullScreen(true);}第一個if檢查首選項以查看是否設置了全屏。第二個if查看是否選擇了第一個監視器之外的另一個監視器。它是 1,所以它應該是第二個顯示器。程序循環遍歷所有屏幕并嘗試移動程序,然后將全屏顯示。我知道坐標是一樣的,但沒有骰子,它仍然在主屏幕上全屏顯示。請幫忙。
查看完整描述

1 回答

?
回首憶惘然

TA貢獻1847條經驗 獲得超11個贊

我不知道我是否真正理解您的問題,但是如果您有兩個屏幕,為什么要循環顯示屏幕?為什么不使用與屏幕相關的信息在位置二/索引之一ObservableList?我發布了一個示例應用程序,演示如何在第二臺顯示器上全屏顯示。


import javafx.application.Application;

import javafx.collections.ObservableList;

import javafx.event.ActionEvent;

import javafx.geometry.Rectangle2D;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.layout.StackPane;

import javafx.scene.layout.VBox;

import javafx.stage.Screen;

import javafx.stage.Stage;


/**

 *

 * @author blj0011

 */

public class JavaFXApplication257 extends Application

{


    @Override

    public void start(Stage primaryStage)

    {

        ObservableList<Screen> screens = Screen.getScreens();//Get list of Screens

        Button btn = new Button();

        btn.setText("Full Screen - Screen 1");

        btn.setOnAction((ActionEvent event) -> {

            Rectangle2D bounds = screens.get(0).getVisualBounds();

            primaryStage.setX(bounds.getMinX());

            primaryStage.setY(bounds.getMinY());

            primaryStage.setFullScreen(true);

            //primaryStage.setWidth(bounds.getWidth());

            //primaryStage.setHeight(bounds.getHeight());

        });


        Button btn2 = new Button();

        btn2.setText("Full Screen - Screen 2");

        btn2.setOnAction((ActionEvent event) -> {

            if (screens.size() > 0) {

                Rectangle2D bounds = screens.get(1).getVisualBounds();

                primaryStage.setX(bounds.getMinX());

                primaryStage.setY(bounds.getMinY());

                primaryStage.setFullScreen(true);

                //primaryStage.setWidth(bounds.getWidth());

                //primaryStage.setHeight(bounds.getHeight());

            }

        });


        StackPane root = new StackPane();

        root.getChildren().add(new VBox(btn, btn2));


        Scene scene = new Scene(root, 300, 250);


        primaryStage.setTitle("Hello World!");

        primaryStage.setScene(scene);

        primaryStage.show();

    }


    /**

     * @param args the command line arguments

     */

    public static void main(String[] args)

    {

        launch(args);

    }


}



查看完整回答
反對 回復 2021-09-12
  • 1 回答
  • 0 關注
  • 186 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號