Java Swing应用程序消息对话框帮助 [英] Java Swing application Message dialog help

查看:146
本文介绍了Java Swing应用程序消息对话框帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Java Swing应用程序。我需要创建一个如图所示的对话框。我不知道这个名字;我无法解释,所以我附上了一张照片。
请告诉我这是什么以及如何在我的GUI应用程序中创建它。

I am working on a Java Swing application. I need to create a dialog like that shown in the figure. I do not know the name for this; I can not explain, so I am attaching a picture. Please tell what this is called and how I can create it in my GUI application.

推荐答案

皮肤猫的方法不止一种

public final class JDialogDemo {
    private static BufferedImage bi;

    public static void main(String[] args){
        try {
            loadImage();

            SwingUtilities.invokeLater(new Runnable(){
                @Override
                public void run() {
                    createAndShowGUI();
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void loadImage() throws IOException{
        bi = ImageIO.read(JDialogDemo.class.getResource("../resource/close-icon.png"));
    }

    private static void createAndShowGUI(){
        final JDialog dialog = new JDialog();
        dialog.setUndecorated(true);

        final JPanel panel = new JPanel(){
            @Override
            public Dimension getPreferredSize(){
                return new Dimension(400, 40);
            }
        };
        panel.setBorder(BorderFactory.createLineBorder(Color.GRAY));
        panel.setBackground(new Color(238, 221, 130));
        panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));

        final JLabel closeLabel = new JLabel();
        closeLabel.setIcon(new ImageIcon(bi));
        closeLabel.addMouseListener(new MouseAdapter(){
            @Override
            public void mouseClicked(MouseEvent e){
                dialog.dispose();
            }
        });

        panel.add(new JLabel("There are deleted items that used to be in this folder."));
        panel.add(Box.createHorizontalGlue());
        panel.add(closeLabel);
        dialog.add(panel);
        dialog.pack();
        dialog.setLocationRelativeTo(null);
        dialog.setVisible(true);
    }
}

这只是一个演示。无论如何,请随意定制。

This is simply a demonstration. Feel free to tailor this however you like.

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

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