Java Swing application message dialog help

I'm working on Java Swing applications I need to create a dialog box as shown in the figure I don't know the name; I couldn't explain, so I attached a photo

Solution

There is more than one way to skin a cat

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 @R_16_2419@Layout(panel,@R_16_2419@Layout.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(@R_16_2419@.createHorizontalGlue());
        panel.add(closeLabel);
        dialog.add(panel);
        dialog.pack();
        dialog.setLocationRelativeTo(null);
        dialog.setVisible(true);
    }
}

This is just a demonstration In any case, please feel free to customize

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>