在双显示器配置中的特定屏幕中显示 JFrame [英] Show JFrame in a specific screen in dual monitor configuration

查看:32
本文介绍了在双显示器配置中的特定屏幕中显示 JFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个双显示器配置,如果找到的话,我想在特定显示器上运行我的 GUI.我尝试通过我的屏幕设备的 GraphicConfiguration 对象创建我的 JFrame 窗口,但它不起作用,框架仍显示在主屏幕上.

I have a dual monitor config and I want to run my GUI in a specific monitor if it is found. I tried to create my JFrame window passing a GraphicConfiguration object of my screen device, but it doesn't work, frame still display on the main screen.

如何设置必须显示我的框架的屏幕?

How can I set the screen where my frame must be displayed?

推荐答案

public static void showOnScreen( int screen, JFrame frame )
{
    GraphicsEnvironment ge = GraphicsEnvironment
        .getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    if( screen > -1 && screen < gs.length )
    {
        gs[screen].setFullScreenWindow( frame );
    }
    else if( gs.length > 0 )
    {
        gs[0].setFullScreenWindow( frame );
    }
    else
    {
        throw new RuntimeException( "No Screens Found" );
    }
}

这篇关于在双显示器配置中的特定屏幕中显示 JFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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