Java全屏模式对话框 [英] Java Fullscreen Modal Dialogs

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

问题描述

如何创建自定义模态JDialog用作内部对话框?用于FullscreenExclusiveMode.

How does one create a custom modal JDialog that can be used as an internal dialog? For use in FullscreenExclusiveMode.

我有一个JScrollPane(带有一个巨大的滚动条),上面装满了巨大的按钮,像这样:

I have a JScrollPane (with a huge scrollbar) full of huge buttons like so:

+----------------------+------+
|         FOO          |  /\  |
|______________________+------+
|                      |______|
|         BAR          |      |
|______________________|  ==  |
|                      |______|
|         BIZ          |      |
+______________________+------+
|                      |  \/  |
|----------------------+------+

我需要用户使用巨型滚动条滚动浏览并点击特定按钮以选择它并关闭对话框.该对话框处于全屏独占模式.关闭按钮需要被禁用,并且不需要确定按钮或取消按钮,无论他们单击哪个按钮都需要更新值,然后在对话框上调用frame.dispose().

I need the user to use the giant scrollbar to scroll through and tap a particular button to select it and close the dialog. The dialog is in fullscreen exclusive mode. The close button needs to be disabled and it needs to not have okay or cancel buttons, whichever button they click needs to update a value and then call frame.dispose() on the dialog.

现在我正在使用内部框架,但是由于没有使用JDesktop,所以该框架没有在其他所有部件之前弹出.我也尝试过JDialog,但是它最小化了应用程序.

Right now I'm using an internal frame but the frame isn't popping up in front of everything else because I'm not using a JDesktop. I've also tried JDialog but it minimizes the app.

JOptionPane.showInternalDialog()可以工作,但是如何以相同的方式构造自己的内部对话框以便可以显示它们呢?如果我制作了一个内部框架,然后将其添加到组件中,则它只是位于该组件内,而不是位于所有组件之上.

JOptionPane.showInternalDialog() works but how do I construct my own internal dialogs in the same fashion so that they can be shown? If I make an internal frame and then add it to a component it just sits within that component and not on top of everything.

浏览了这些类并尝试了弹出工厂,但是弹出窗口似乎无法在全屏模式下可靠地工作.

Looked through those classes and tried the popup factory but the popups don't seem to work reliably in fullscreen.

尝试使用JOptionPane.createInternalFrame()这是我正在使用的演示,但它似乎还没有运行.

Trying JOptionPane.createInternalFrame() here is the demo I'm working with but it doesn't seem to be working yet.

public class FullscreenDialog {

    public static final void main(final String[] args) throws Exception {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());//uses os window manager

        JPanel panel = new JPanel();
        panel.setPreferredSize(new Dimension(800,600));

        final JLabel label = new JLabel("Something to say.");
        panel.add(label);
        final JFrame fullscreenFrame = new JFrame();
        fullscreenFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        fullscreenFrame.setUndecorated(true);//To remove the bars around the frame.
        fullscreenFrame.setResizable(false);//resizability causes unsafe operations.
        fullscreenFrame.setContentPane(panel);
        fullscreenFrame.validate();
        GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(fullscreenFrame);//actually applies the fullscreen.

        final JOptionPane optionPane = new JOptionPane();
        optionPane.add(new JLabel("Some alert"));
        final JButton button = new JButton();
        button.setText("Press me.");
        button.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                label.setText("worked");
                optionPane.setValue(button);
            }
        });
        JInternalFrame frame  = optionPane.createInternalFrame(panel, "Internal Dialog");
        frame.setVisible(true);
    }
}

推荐答案

JOptionPane构造函数的message参数可以是Component以及字符串,例如可能是您的JScrollPane.

The message argument to the JOptionPane constructor can be a Component as well as a string, e.g. it could be your JScrollPane.

要从选项窗格中删除标准按钮,请使用空数组调用setOptions(Object[]).

To remove the standard buttons from the option pane, call setOptions(Object[]) with an empty array.

这篇关于Java全屏模式对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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