JOptionPane Icons

Hello, all!
JOptionPane icons are usually available by invoking
UIManager.getIcon("OptionPane.errorIcon");
UIManager.getIcon("OptionPane.informationIcon");
UIManager.getIcon("OptionPane.questionIcon");
UIManager.getIcon("OptionPane.warningIcon");This all works well, except for native GTK Look & Feel, where nulls are returned (all is ok with synthetic GTK Look & Feel). How can I fix the problem?

You are using OK_OPTION when you should be using a message type:
JOptionPane.showMessageDialog(MainFrame.getInstance(), message,
windowTitle, JOptionPane.INFORMATION_MESSAGE);
there are
ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE

Similar Messages

  • How to change The Standard JOptionPane Icon?

    in this simple code
    i want to change the Standard JOptionPane icon to a different icon
    how could it be?
    thank you
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.WindowListener;
    import java.awt.event.WindowEvent;
    import javax.sound.sampled.*;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import javax.swing.ImageIcon;
    import javax.swing.Icon;
    import java.awt.event.*;
      public class MyFrame extends JFrame 
    JLabel label=new JLabel("Hello");
      MyInner inner;
          MyFrame ()
            setupGUI();
        private void setupGUI()
           JFrame f =new JFrame();
        //   f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
           f.setTitle("Window Event");
            f.setSize(550,350);
            f.setResizable(false);
            f.setLayout(new BorderLayout());
            f.add("Center",label);
            f.show(true);
             inner=new  MyInner();
             f.addWindowListener(inner);
                   class MyInner extends WindowAdapter
           public void windowClosing(WindowEvent ee)
                         Toolkit tool = Toolkit.getDefaultToolkit();
                  tool.beep();
                      JOptionPane.showMessageDialog(null, "Nice Work! " );
                      System.exit(0);
          public  static void main(String[]args)
             MyFrame frame=new MyFrame ();
    }

    For instance:
        class MyInner extends WindowAdapter
            public void windowClosing(WindowEvent ee)
                Toolkit tool = Toolkit.getDefaultToolkit();
                tool.beep();
                JOptionPane.showMessageDialog(null, "Nice Work! ");
                ImageIcon myImageIcon = new ImageIcon("myPic.jpg"); // needs proper path here
                JOptionPane.showMessageDialog(null, "Better Work!", "Dang, I'm smart!", JOptionPane.ERROR_MESSAGE, myImageIcon);
                System.exit(0);
        }

  • Using JoptionPane icon in other dialogs

    I was originally using a ProgressMonitor. but this wasn't flexible enough so i created my own subclass of JDialog which contained a JProgressBar.
    This work fine but I want it to display the Information Icon that you get with ProgressMonitor and some JoptionPanes. How can I do this without subclassing JOptionPane.

    I think....
    Icon icon = UIManager.getDefaults().getIcon(key);
    where key is one of...
    OptionPane.errorIcon
    OptionPane.informationIcon
    OptionPane.questionIcon
    OptionPane.warningIcon

  • JOptionPane Icon

    the below code will show a JOptionPane with a panel containing 3 textfields.
    but the icon of JOptionPane is always (X) can i change it to (!) or something else . . . looks like error.
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class test11 extends JFrame
         public test11()
              panel p1 = new panel();
              JOptionPane.showInputDialog(null,p1,"Input Menu",JOptionPane.OK_OPTION);
              System.out.println(p1.t1.getText()+"\t"+p1.t2.getText()+"\t"+p1.t3.getText()); 
         public static void main(String[] args)
         test11 t = new test11();
         t.setVisible(true);
         t.setDefaultCloseOperation(EXIT_ON_CLOSE);
         t.setSize(500,500);
    class panel extends JPanel
         JTextField t1,t2,t3;
         JLabel l1,l2,l3;
         public panel()
              setLayout(new GridLayout(3,2));
              setSize(100,100);
              l1 = new JLabel("enter user: ");
              t1 = new JTextField(30);
              l2 = new JLabel("enter password: ");
              t2 = new JTextField(30);
              l3 = new JLabel("enter url :");
              t3 = new JTextField(30);
              add(l1); add(t1); add(l2);  add(t2); add(l3); add(t3);
    }

    OK_OPTION is not used this way but rather to check the return value of one of the other JOptionPane objects, the showConfirmDialog. The JOptionPane API will tell you what you need to know. For instance:
    JOptionPane.showInputDialog(null, p1, "Input Menu",
       JOptionPane.INFORMATION_MESSAGE);or try JOptionPane.INFORMATION_MESSAGE
    Edited by: Encephalopathic on Apr 30, 2009 2:53 PM

  • JOptionPane: odd key behaviour

    I use the JOptionPane like
    int answer = JOptionPane.showConfirmDialog(parentComponent, question, title, JOptionPane.YES_NO_OPTION);This works well when using the mouse. But when the dialog is open, i can't move with the keyboard cursor keys - only with the tab key. In additon, i just can select the option with the SPACE key - if i press ENTER (which most users do when using the keyboard), the selected option is NOT selected, but the default one. (Which can be fatal for a request "Do you want to delete this record": user moves to "no" and presses the enter key => the "yes" option is selected!)

    I had the same problem ... looking some info and ideas on forums I developed a solution for that ... it's a class extendes from JOptionPane ... and you could use it instead of the formal JOptionPane.
    I customized the ENTER key to have a behavior of the SPACEBAR key in a JOptionPane.
    ==================================================================================
    Archive Name: optionPane.java
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class optionPane extends JOptionPane
    private JButton boton;
    private int valor;
    private Object[] opciones;
    /* Parameters:
    message : message to display
    messageType : the same for an JOptionPane
    icon : icon to be displayed
    nomOpciones : array of names for the buttons.
    public optionPane(Object message, int messageType, Icon icon, Object[] nomOpciones)
    super(message,messageType);
    opciones = customBoton(nomOpciones);
    setIcon(icon);
    setOptions(opciones);
    setInitialValue(opciones[0]);
    valor = -1;
    // Method that customized the behavior of the button, add the ENTER key behavior
    public static void enterPressesWhenFocused(JButton button)
    button.registerKeyboardAction(
    button.getActionForKeyStroke(
    KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false)),
    KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false),
    JComponent.WHEN_FOCUSED);
    button.registerKeyboardAction(
    button.getActionForKeyStroke(
    KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true)),
    KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true),
    JComponent.WHEN_FOCUSED);
    //Method that add the customized button into an array of objects.
    public Object[] customBoton(Object[] lista)
    Object[] listaCustom = new Object[lista.length];
    for (int i=0; i<lista.length; i++)
    String nombre = (String) lista;
    boton = new JButton(nombre);
    enterPressesWhenFocused(boton);
    boton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    actEnterActionPerformed(evt);
    listaCustom[i] = boton;
    return listaCustom;
    private void actEnterActionPerformed(ActionEvent evt) {
    // When the button is pressed , the value of its position in the array of buttons is recovered.
    for(int i=0; i<opciones.length; i++)
    String nomBoton = ((JButton) opciones[i]).getText().trim();
    if (((JButton) opciones[i]).getText().equals(((JButton)evt.getSource()).getText()))
    valor = i;
    break;
    // Dispose the JDialog where the optionPane is contained.
    ((JDialog)getRootPane().getParent()).dispose();
    public int getOpcion()
    //Method that return the postion of the option in the array of buttons
    return valor;
    Now ... there's an example how I called that customized JOptionPane
    // message to be displayed
    String message = "Se eliminar� el Conteo Nro. "+tblConsulta.getValueAt(tblConsulta.getSelectedRow(),0);
    // array with the names to be displayed in the optionPane buttons and the index that have each name //detemines , the numer that the optionPane recovers.
    Object[] nomOpciones = new Object[]{"Si","No"};
    //Instance of optionPane
    optionPane opcion = new optionPane(message,JOptionPane.QUESTION_MESSAGE,null,nomOpciones);
    //Inserting in a JDialog
    opcion.createDialog(frame, "Mensaje").setVisible(true);
    //Recovering the index of the option selected
    int respuesta = opcion.getOpcion();
    if I pressed the button labeled with "Si", the optionPane give me a number 0
    if I pressed the button labeled with "No", the optionPane give me a number 1
    If you'd noticed ... those number are the position of those labels in the array of names
    Well I guess these code coul help you ...
    Cyap ... and good luck
    mkrick_java
    [email protected]

  • Features of JOptionPane

    I am making an installer for my application, and it communicates with the user via a few simple popups, sometimes just with an ok button, sometimes yes/no buttons.
    i have been using JOptionPane.showMessageDialog() and JOptionPane.showConfirmDialog(). The problem with these popups is that they don't show up as a JFrame. by that, I mean that [in windows] nothing shows up in the taskbar, so sometimes the panes show up behind other applications that are already running, and you cant tell that a popup is even displayed for you.
    i am experimenting with making a JFrame popUp a message with ok or yes/no buttons. this way, something shows up on the taskbar (and I can also put an icon with the frame via setIconImage(new ImageIcon("icon.gif").getImage());).
    but now my popups seems rather plain without the information or warning icons that are built in to JOptionPane.
    is there any way I can have a JOptionPane show up in the taskbar and have a custom icon displayed not with the message, but with the frame itself, keeping the respective JOptionPane icon that is shown with the message/confrim dialog?
    if not, what do you think would be my best option?
    thanks.

    there is no jframe. there is no gui.
    basically its an auto extracting jar, and it lets the user know when its done via a popup with an ok button. it then asks the user a yes/no question...."do you want to run the extracted app now?"
    the problem is these popups are not always seen, so the user is left thinking they need to run the extractor.jar again and they keep double-clicking...

  • JOptionPane.showMessage doesn't display message & icon in Solaris

    Hi huys,
    JOptionPane.showMessageDialog doesn't display message & icon in Solaris, but display is proper through XWin.
    Any help is appreciated.
    Edited by: Quest_4_Java on Oct 29, 2008 12:15 AM

    There's a program called DockStar that lets you put badges on the dock icon for different folders. It's shareware and available here: http://www.ecamm.com/mac/dockstar/
    I've got a smart mailbox named "Unread messages" that just collects ... all my unread messages (I do a lot of automagic sorting) and then have DockStar show how many messages are in that smart folder.

  • Custom icon for JOptionPane.showInputDialog

    As a novice who's wading through Deitel's 'Java how to program', using java2 and j2sdk1.4.1 on JCreator Pro. I want to use my own icons on a small proggie i've written. I know that the format is:
    showInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue)
    however this doesn't tell me how to write the code. how do i change the default '?' icon for my own icon?
    thanks for any help
    rgds
    adambi

    This should help you also
                ImageIcon ico = new ImageIcon("drag2.jpeg");
                Frame frame = new Frame();
                Object[] options = {"Yes, please",
                        "No, thanks",
                        "No eggs, no ham!"};
              JOptionPane.showInputDialog(frame,
              "What some eggs ?.",
              "My title",JOptionPane.ERROR_MESSAGE,ico,options,
        options[2]);also here is a good link for ya on dialogs
    http://java.sun.com/j2se/1.4/docs/api/
    GOOD LUCK

  • How to change the icon of JOptionPane and JFileChooser in swing

    Hi,
    Does any body know how to change the icon of JOptionPane and JFileChooser in swing.
    Please help me out in this.
    Thanx in advance.

    Try this
    import javax.swing.*;
    import java.awt.event.*;
    public class Untitled4 {
      public Untitled4() {
      public static void main(String[] args) {
        ImageIcon i = new ImageIcon("C:/TestTree/closed.gif");
        JOptionPane p = new JOptionPane();
        p.setMessage("This JOptionPane has my icon");
        p.setMessageType(JOptionPane.QUESTION_MESSAGE);
        p.setOptionType(JOptionPane.YES_NO_CANCEL_OPTION);
        final JDialog d = p.createDialog("test");
        d.setIconImage(i.getImage());
        d.setVisible(true);
        d.setModal(true);
        if(Integer.parseInt(p.getValue().toString()) == JOptionPane.YES_OPTION) {
            System.out.println("You Clicked Yes");
    }

  • Official way to reuse icons from JOptionPane

    I want to use some of the icons that JOptionPane uses in one of my own dialogs. Is there a safe and official way of doing this? I am pretty new to Java and JFC so I could be missing something obvious. I did a search in this forum and found lots of discussion on how to use your own icons instead of the ones JOptionPane provides.
    I know I can poke around the library .jar files and find the images and then use code like this:
    URL imageURL = loadFromClassLocation.getResource (iconFileName);to load the image but my instincts say that is too fragile. Is there an official way to do this? Perhaps a property defined in the look and feel?
    thanks,
    Ian

    UIManager.getIcon("OptionPane.errorIcon")
    UIManager.getIcon("OptionPane.informationIcon")
    UIManager.getIcon("OptionPane.warningIcon")
    UIManager.getIcon("OptionPane.questionIcon")
    The easiest way to find things like this is to look at the source code for the component class and for the component class's ui. Eventually, the resources will be pulled through the ui manager and you can get the key strings. I found these strings in BasicOptionPaneUI::getIconForType.

  • JOptionPane getting it's icon

    I have created a JOptionPane and I am trying to get it's icon. I read that the icon was driven by the message type so why is the icon null? Better yet, how can I get get the error icon that it uses. That's my goal. This is what I have done
    String message = "msg";
    JOptionPane pane = new JOptionPane(message, JOptionPane.ERROR_MESSAGE);
    JDialog dlg = pane.createDialog(null, "title");
    Icon icon = pane.getIcon();
    //the Icon is null  BOOOO 
    //if I add do this then the icon shows up... uhm... icon is bound in the show.  How is does show get it?
    dlg.show();

    you can use :
    UIManager.getIcon("OptionPane.questionIcon")
    UIManager.getIcon("OptionPane.errorIcon")
    UIManager.getIcon("OptionPane.informationIcon")
    UIManager.getIcon("OptionPane.warningIcon")

  • Setting the default icons for JOptionPane

    i have my own LookAndFeel and i'm trying to set the icons of JOptionPane but it doesn't work, why?
    Icon errorIcon =  new ImageIcon( "images/EbooksIconMedium.png" );
    table.put( "OptionPane.errorIcon", errorIcon );
    table.put( "OptionPane.informationIcon", errorIcon );
    table.put( "OptionPane.questionIcon", errorIcon );
    table.put( "OptionPane.warningIcon", errorIcon );
    ....

    Hello Dmitry,
    There is no customizing for this - atleast to my knowledge.
    However, you should have to redo the settings again and again unless you are continuously re-sizing the main window.
    Cheers
    Aneesh

  • Change The Icon Of JOptionPane

    Can anybody tell me how can I chnage the Icon of JOptionPane ,
    I would like to chnage the default Icons come with Java, I want my own Icons to be displayed
    Thanx in advance
    pritesh

    hi,
    just use those static showXXXDialog() methods that expect a javax.swing.Icon as parameter, such as:
    JOptionPane.showMessageDialog(null, "My message", "My title", JOptionPane.INFORMATION_MESSAGE, new ImageIcon("info.gif"));
    Or use the showOptionDialog() method that provides similar features.
    sincerely Michael

  • Display an icon(question,warning,etc.) inside JDialog(like in JOptionPane)

    Hello,
    because JOptionPane can't use a JPasswordField as the input component, I created a JDialog prompting the user for a password. Now I can't figure out how to show that nice look-and-feel style icon inside the dialog (the question mark that is shown when you use messageType=QUESTION_MESSAGE in JOptionPane). Shortly, this is what I have and this is what I want to get... I tried this:
    dlg.getRootPane().setWindowDecorationStyle(JRootPane.QUESTION_DIALOG)But it does nothing. Could you help me, please?
    Thank you
    Ondra

    Still it doesn't answer my question: how to display the LAF icon inside a JDialog.Huh?import javax.swing.*;
    public class OptionPanePassword {
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
                new OptionPanePassword().makeUI();
       public void makeUI() {
          JLabel label =new JLabel("Enter Password: ");
          JPasswordField field = new JPasswordField(15);
          JPanel panel = new JPanel();
          BoxLayout layout = new BoxLayout(panel, BoxLayout.X_AXIS);
          panel.setLayout(layout);
          panel.add(label);
          panel.add(field);
          JOptionPane.showConfirmDialog(null, panel, "",
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
    }db

  • Change Coffee cup icon on JDialog & JOptionPane

    I try to change the coffee cup icon on my JDialog and JOptionPane.
    My JDialog box does not load the Parent Icon (JFrame icon), and not even show a coffee cup icon.
    My JOptionPane would just show a coffee cup icon, eventhough its parent is the above JDialog with no icon.
    Is there anyone know how to fix this?
    I'd like show my icon on the JOptionPane instead of the coffee cup icon.
    And also to show my icon on the JDialog instead of nothing, not even a coffee icon.
    Any help is appreciated.
    CL

    Passing a parent with the desired icon to the JDialog/JOptionPane should solve your problem, however there is a bug in swing that prevents any icon from showing in the titlebar if a JDialog is made non-resizable (through a call to setResizable(false)).
    The bug adatabse says that this has been resolved but I am using jdk 1.3.1 and continue to have this problem.

Maybe you are looking for

  • Missing folder in list view. Mac OSX 10.4.11

    I have an external Firewire Hard Drive with 10 folders on it. One of the folders contains around 100GB of video files. This folder does not appear in the list view. All the other folders appear as normal. In ccon or column view the folder is there. I

  • 'thin' fonts on an external monitor

    Hi, I am using an x200 with an external LG monitor 1680 x 1050, 32bit with 120DPI font. The text seems very 'thin / weak' and is a challenge to read. Is there away of 'blackening' the text to make it nore legible ?

  • "the system cannot find the path specified" followed by x:\windows\system32

    Hi I have an HP pavilion g6, my recovery goes perfect up to this point a black window pops up with the system cannot find the path specified what is the reasoning for this I have a new hard drive and CD/DVD drive is there something else that is wrong

  • Response ID Control in Mailing Campaign

    Hi, Doing Mailing Campaign we can control throug Tracking via Target Site(++) how many times customer has accessed to the URL(CRMD_EMAIL_LIST). What we really need is if there is any way to pick up this BP´s and enclose in a Target Group to be used l

  • MSS Configuration problem.

    Hi all,    i am on ECC 5.0 and ep 6.0 and i uploaded business package "BP_ERP4MSS0_2-10002991.zip" and patch  "MSS10_0-10002964.sca." Right now i am able to see all the iviews in "MY STAFF" and "MY BUDGET". But when i am selecting any area groups its