簡體   English   中英

在SECOND屏幕上的javafx全屏

[英]javafx full screen on SECOND screen

對於我的生活,我似乎無法得到這方面的幫助。 我有一個JavaFX屏幕,我試圖在我的第二台顯示器上顯示全屏。 我根據其他建議嘗試了以下但無濟於事。 我知道坐標是正確的但它在我的MAIN顯示器上全屏顯示。 請幫忙。

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,所以應該是第二個監視器。 程序循環遍歷所有屏幕並嘗試移動程序,然后全屏顯示。 我知道坐標是相同但沒有骰子,它仍然在主屏幕上全屏顯示。 請幫忙。

我不知道我是否真的理解你的問題,但是如果你有兩個屏幕,為什么要在屏幕上循環? 為什么不直接使用與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);
    }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM