且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将图像添加到JOptionPane

更新时间:2023-12-06 16:33:04

JOptionPane 是一个非常灵活的API。

JOptionPane is a very flexible API.

你的第一个停靠点应该是 Java API Docs Java Trails ,具体的如何使用Dialogs

Your first port of call should be the Java API Docs and the Java Trails, specific How to use Dialogs

public class TestOptionPane04 {

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                }

                ImageIcon icon = new ImageIcon(TestOptionPane04.class.getResource("/earth.png"));
                JOptionPane.showMessageDialog(
                        null,
                        "Hello world",
                        "Hello", JOptionPane.INFORMATION_MESSAGE,
                        icon);
                JOptionPane.showMessageDialog(
                        null,
                        new JLabel("Hello world", icon, JLabel.LEFT),
                        "Hello", JOptionPane.INFORMATION_MESSAGE);

            }
        });
    }
}