Java 全屏模式对话框

发布于 2024-11-09 08:34:38 字数 2427 浏览 0 评论 0原文

如何创建一个可用作内部对话框的自定义模式 JDialog?用于全屏独占模式。

我有一个 JScrollPane (带有巨大的滚动条),里面充满了巨大的按钮,如下所示:

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

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

现在我正在使用内部框架,但该框架不会在其他所有内容前面弹出,因为我没有使用 JDesktop。我也尝试过 JDialog 但它最小化了应用程序。

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

编辑:查看了这些类并尝试了弹出窗口工厂,但弹出窗口似乎无法在全屏下可靠地工作。

编辑:尝试 JOptionPane.createInternalFrame() 这里是我正在使用的演示,但它似乎还没有工作。

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

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

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

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

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.

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() 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.

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时常饿 2024-11-16 08:34:38

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

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

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

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

初见你 2024-11-16 08:34:38

JOptionPane.showXXXDialog(...) 允许在创建自定义内部对话框时进行大量自定义。

JOptionPane.showXXXDialog(...) allows for a lot of customizations in creating a custom internal dialog.

情绪少女 2024-11-16 08:34:38

试试这个..

.
.
.
            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");
                    fullscreenFrame.invalidate();
                    fullscreenFrame.repaint();
                    optionPane.setValue(button);
                }
            });
            JInternalFrame frame  = optionPane.createInternalFrame(panel, "Internal Dialog");
            frame.getContentPane().removeAll();
            JPanel pnl = new JPanel(new BorderLayout());
            pnl.add( button, BorderLayout.SOUTH );
            pnl.add( new JScrollBar(), BorderLayout.CENTER );
            frame.getContentPane().add( pnl );
            frame.setVisible(true);

try this..

.
.
.
            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");
                    fullscreenFrame.invalidate();
                    fullscreenFrame.repaint();
                    optionPane.setValue(button);
                }
            });
            JInternalFrame frame  = optionPane.createInternalFrame(panel, "Internal Dialog");
            frame.getContentPane().removeAll();
            JPanel pnl = new JPanel(new BorderLayout());
            pnl.add( button, BorderLayout.SOUTH );
            pnl.add( new JScrollBar(), BorderLayout.CENTER );
            frame.getContentPane().add( pnl );
            frame.setVisible(true);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文