第二屏幕上的javafx全屏 [英] javafx full screen on SECOND screen

查看:332
本文介绍了第二屏幕上的javafx全屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一生中,我似乎无法获得任何帮助.我有一个JavaFX屏幕,并且试图在第二台显示器上全屏显示.我根据其他建议尝试了以下方法,但无济于事.我知道坐标正确,但是可以在我的MAIN显示器上全屏显示.请帮忙.

For the life of me, I can't seem to get help on this. I have a JavaFX screen and I am trying to get to show fullscreen on my 2nd monitor. I tried the following based on other recommendations but to no avail. I know the coordinates are right but it KEEPS going full screen on my MAIN monitor. Please help.

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,因此应该是第二台显示器.该程序循环遍历所有屏幕,然后尝试移动该程序,然后将进入全屏状态.我知道坐标是相同的,但没有骰子,它仍然在主屏幕上全屏显示.请帮忙.

The first if checks a preference to see if fullscreen is set. the 2nd if sees if another monitor besides the first one was selected. It's 1, so that should be the 2nd monitor. The program loops through all screens and tries to move the program and THEN will go full screen. I know the coordinates are the same but no dice, it still goes full screen on the main screen. Please help.

推荐答案

我不知道我是否真正了解您的问题,但是如果您有两个屏幕,为什么要循环浏览这些屏幕?为什么不只使用与ObservableList的位置2/索引1中的屏幕相关的信息?我正在发布一个示例应用程序,该应用程序演示了如何在第二个监视器上显示全屏.

I don't know if I truly understand your problem, but if you have two screens, why loop through the screens? Why not just use the info associated with the screen in position two/index one of the ObservableList? I am posting a sample app that demos how to display full screen on a second monitor.

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

}

这篇关于第二屏幕上的javafx全屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆