[英]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.