Java 从JOptionPane中删除图标
如何从Java 从JOptionPane中删除图标,java,image,swing,joptionpane,imageicon,Java,Image,Swing,Joptionpane,Imageicon,如何从作业窗格中删除图标 ImageIcon icon = new ImageIcon(image); JLabel label = new JLabel(icon); int result = JOptionPane.showConfirmDialog((Component) null, label, "ScreenPreview", JOptionPane.OK_CANCEL_OPTION); 您可以直接指定邮件的外观 您的代码将采用默认代码,而此代码将使用“PLAIN_MESSAGE”样
作业窗格
中删除图标
ImageIcon icon = new ImageIcon(image);
JLabel label = new JLabel(icon);
int result = JOptionPane.showConfirmDialog((Component) null, label, "ScreenPreview", JOptionPane.OK_CANCEL_OPTION);
您可以直接指定邮件的外观 您的代码将采用默认代码,而此代码将使用“PLAIN_MESSAGE”样式,该样式缺少图标。组件的行为保持不变
JOptionPane.showConfirmDialog(null, label, "ScreenPreview", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
更多信息:使用下面的透明图标(与黑色“飞溅图像”相反),这相当容易。尽管需要注意的是,尽管选项窗格在显示方式上提供了一些“摇摆空间”,但要更改一些内容,使用
JDialog
会很快变得更容易
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
class IconFree {
public static void main(String[] args) {
Runnable r = new Runnable() {
@Override
public void run() {
// A transparent image is invisible by default.
Image image = new BufferedImage(
1, 1, BufferedImage.TYPE_INT_ARGB);
JPanel gui = new JPanel(new BorderLayout());
// ..while an RGB image is black by default.
JLabel clouds = new JLabel(new ImageIcon(new BufferedImage(
250, 100, BufferedImage.TYPE_INT_RGB)));
gui.add(clouds);
JOptionPane.showConfirmDialog(null, gui, "Title",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
new ImageIcon(image));
}
};
// Swing GUIs should be created and updated on the EDT
// http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html
SwingUtilities.invokeLater(r);
}
}
写-1代替
JOptionPane.QUESTION\u消息
JOptionPane.PLAIN\u消息?@mishik:JOptionPane.PLAIN\u消息不允许我使用“确定”取消按钮。为什么-1
?这是什么意思?为什么不使用一个JOptionPane
常量呢?它的意思是:JOptionPane.showMessageDialog(父项、消息、状态,-1);因此-1将隐藏与showMessageDialog一起使用的图标。