6

私はこのレイアウトを持っていますJOptionPane:

JCheckBox checkbox = new JCheckBox("Do not show this message again.");
String message = "Level loaded successfully";  
Object[] params = {message, checkbox};  
int n = JOptionPane.showConfirmDialog(p, params, "Draft saving",
     JOptionPane.PLAIN_MESSAGE);  

Icon..の表示以外はすべて問題ありません。

理想的には、アイコンを持たないことを望みます (したがってJOptionPane.PLAIN_MESSAGE) が、default Icon.

どうすればこれを変更できますか?

ジェイソン

4

6 に答える 6

8

アイコン パラメータを受け取るバージョンのメソッドを使用し、アイコンに null を渡します。

于 2011-07-03T12:30:06.597 に答える
6

たとえば、期待どおりに動作します

import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;


public class OptionPaneOptions {

    private JPanel options;
    private Object[] items;

    public OptionPaneOptions() {
        options = new JPanel(new GridLayout(0, 3));
        options.add(createOptionPane("Plain Message", JOptionPane.PLAIN_MESSAGE));
        options.add(createOptionPane("Error Message", JOptionPane.ERROR_MESSAGE));
        options.add(createOptionPane("Information Message", JOptionPane.INFORMATION_MESSAGE));
        options.add(createOptionPane("Warning Message", JOptionPane.WARNING_MESSAGE));
        options.add(createOptionPane("Want to do something?", JOptionPane.QUESTION_MESSAGE));
        items = new Object[]{"First", "Second", "Third"};
        JComboBox choiceCombo = new JComboBox(items);
        options.add(titled(new JOptionPane(choiceCombo,
                JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION), "Question Message"));
        JFrame frame = new JFrame("JOptionPane'Options");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(options, BorderLayout.CENTER);
        frame.pack();
        frame.setVisible(true);
    }

    static JOptionPane createOptionPane(String message, int type) {
        JOptionPane pane = new JOptionPane(message, type);
        String title = message;
        if (type == JOptionPane.QUESTION_MESSAGE) {
            title = "Question Message";
            pane.setOptionType(JOptionPane.YES_NO_CANCEL_OPTION);
        }
        return titled(pane, title);
    }

     static <T extends JComponent> T titled(T c, String title) {
        c.setBorder(BorderFactory.createTitledBorder(title));
        return c;
    }

    public static void main(String[] args) {
        OptionPaneOptions test = new OptionPaneOptions();
    }
}
于 2011-07-03T13:02:21.647 に答える
2

使用しているメソッドはアイコンを指定していません。

showConfirmDialog(Component, Object, String, int , int , Icon)も渡すことができる を使用する必要がありIconます。

于 2011-07-03T12:32:41.137 に答える