全屏Swing应用程序前面的JFileChooser [英] JFileChooser in front of fullscreen Swing application

查看:83
本文介绍了全屏Swing应用程序前面的JFileChooser的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有一些与此问题相关的主题(主要是这个未回答的问题(未处理全屏应用).

I know there are some topics relative to this question (mainly this unanswered one and this one which is not handling full screen app).

我基本上尝试了第一个主题示例和可用方法(requestFocus,requestFocusInWindow等)的每种组合,但是JFileChooser始终显示在全屏应用程序的后面.我也尝试更改filechooser的父级(将其自身或父级框架设置为null),但没有成功.

I basically tried every combination of first topic sample and available methods (requestFocus, requestFocusInWindow, ...) but JFileChooser is always displaying behind the fullscreen app. I tried to change filechooser's parent too (setting it to null, itself or the parent frame) with no more success.

有人有没有这个不太特殊的用例的可行示例?还是有一种解决方法可以让用户在全屏应用程序中选择文件?

Have anyone a working example of this not-that-much-particular use case? Or is there a workaround to let user select files in a fullscreen app?

推荐答案

不幸的是,我不能说您是如何实现全屏应用程序的.但我尝试了几件事,并提出了以下建议:

Unfortunately I can't say how you realised the implementation of the fullscreen app. But I tried a few things and came up with this:

import java.awt.Color;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class Gui extends JFrame {

    public Gui() {

        this.setDefaultCloseOperation(EXIT_ON_CLOSE);

        //this.setSize(java.awt.Toolkit.getDefaultToolkit().getScreenSize());
        // Set some charateristics of the frame
        this.setExtendedState(Frame.MAXIMIZED_BOTH);
        this.setBackground(Color.black);
        this.setUndecorated(true);

        JButton a = new JButton("PRESS ME!");

        a.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                JFileChooser fc = new JFileChooser();
                fc.showOpenDialog(getParent());
            }
        });

        this.add(a);

        this.setVisible(true);

    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Gui();
            }
        });
    }
}

请注意,我创建了一个新的JFileChooser,并将当前JFrame的父级作为参数.

Pay attention to the fact, that I created a new JFileChooser with the parent of the current JFrame as parameter.

我现在甚至尝试设置

I now even tried to set

java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(new Gui());

并且没有

this.setUndecorated(true);

它为我工作(获得了不错的全屏视图,并且JFileChooser位于前面).我相信窗户装饰的问题与我的窗户管理器有关(我在gnome中使用linux).

it worked for me (got a nice fullscreen view and the JFileChooser was in the front). I believe the problem with the window decoration is linked to my window manager (I'm using linux with gnome).

希望该解决方案对您有效,如果不能的话: 您能否进一步说明如何创建全屏应用程序?

Hopefully this solution works for you, if not: Could you explain a little bit more, how you create the fullscreen app?

这篇关于全屏Swing应用程序前面的JFileChooser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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