[英]Remove icon from JOptionPane
如何从JOptionPane
删除图标?
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);
更多信息: http : //docs.oracle.com/javase/6/docs/api/javax/swing/JOptionPane.html
通过使用如下透明图标(与黑色'飞溅图像'相反),这相当容易。 虽然注意到虽然选项窗格在显示方式方面提供了一些“摆动空间”,但是要改变一些事情,很快就会变得更容易使用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_MESSAGE
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.