简体   繁体   English

创建带有图像错误消息的jDialog Swing

[英]Create jDialog Swing with a message of error with image

I'm new of Java and I want to do a jDialog that is opening when I push a button in the main JFrame and show a message of error in this way: 我是Java的新手,我想做一个jDialog,当我按下主JFrame中的按钮并以这种方式显示错误消息时,它将打开:

在此处输入图片说明

I can't put the image in another way in NetBeans? 我不能将图像以其他方式放入NetBeans吗? I create in the source package a directory with the image and a try much thing: 我在源代码包中创建了一个包含图像的目录和一个很多尝试:

jDialog1.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
jDialog1.add(new JLabel(new ImageIcon(ImageIO.read(getClass().getResourceAsStream("/img/error_button.png")))));
jDialog1.pack();
jDialog1.setLocationByPlatform(true);

jDialog1.setVisible(true);

Is there a simple way to do this? 有没有简单的方法可以做到这一点?

We can use an option pane for this. 我们可以为此使用一个选项窗格 It includes its own icons according to the type of message (and look and feel). 根据消息的类型(以及外观),它包括自己的图标。

在此处输入图片说明

Exception e = new Exception("Error!");
JOptionPane.showMessageDialog(f, e, e.getMessage(), JOptionPane.WARNING_MESSAGE);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM