> I'm writing my own error msg dialog and want to use the JOptionPane's
> error icon. Pls help
You mean like this:
JOptionPane.showMessageDialog(<parent frame>,"<error message
text>","<error message title>",JOptionPane.ERROR_MESSAGE);
For such basic information about Swing components, you should bookmark
at least Sun's Swing tutorial pages, for example
<http://java.sun.com/docs/books/tutorial/uiswing/components/components.html>.

Signature
-Aki "Sus" Laukkanen
"Älä multa kysy tai mä vastaan!"
"Don't ask me or I'll answer!"
Mikael Flensborg - 27 Apr 2005 09:15 GMT
Aki "Sus" Laukkanen wrote:
>> I'm writing my own error msg dialog and want to use the JOptionPane's
>> error icon. Pls help
[quoted text clipped - 6 lines]
> at least Sun's Swing tutorial pages, for example
> <http://java.sun.com/docs/books/tutorial/uiswing/components/components.html>.
Think the question is misunderstood... He wants to use the ICON used in
JOptionPane in other contexts, and NOT the JOptionPane itself... I have
been looking for a way to do it too.. So far with no success.
/Mikael
Thomas Weidenfeller - 27 Apr 2005 10:56 GMT
> Think the question is misunderstood... He wants to use the ICON used in
> JOptionPane in other contexts, and NOT the JOptionPane itself... I have
> been looking for a way to do it too.. So far with no success.
AFAIK there is no official way, the icons are not part of the public
API. You have a number of alternatives:
- Sun's icon repository contains some of them (but not all). If your
icon is there, you could bundle the icon GIF and use that instead.
- You could look through the UI defaults. Sun's VMs uses some properties
to point to the icons. However, this is an implementation detail, and
other VM vendors might do it completely different.
- You could subclass BasicOptionPaneUI to get access to its getIcon...()
method (I forgot the exact name). That method should be capable of
delivering instances of the icons. However, BasicOptionPaneUI has for
sure side-effects when one creates an instance of it. You have to check
if they affect you.
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
> I'm writing my own error msg dialog and want to use the JOptionPane's
> error icon. Pls help
UIManager.getIcon("OptionPane.errorIcon");
For other icons, see following program:
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
public class OptionPaneIcons {
public static void main(String[] args) {
JPanel jContentPane = new JPanel();
jContentPane.setLayout(new FlowLayout());
JLabel jLabel1 = new JLabel();
jLabel1.setIcon(UIManager.getIcon("OptionPane.questionIcon"));
jContentPane.add(jLabel1, null);
JLabel jLabel2 = new JLabel();
jLabel2.setIcon(UIManager.getIcon("OptionPane.warningIcon"));
jContentPane.add(jLabel2, null);
JLabel jLabel3 = new JLabel();
jLabel3.setIcon(UIManager.getIcon("OptionPane.errorIcon"));
jContentPane.add(jLabel3, null);
JLabel jLabel4 = new JLabel();
jLabel4.setIcon(UIManager.getIcon("OptionPane.informationIcon"));
jContentPane.add(jLabel4, null);
JFrame application = new JFrame();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.setContentPane(jContentPane);
application.pack();
application.setLocationRelativeTo(null);
application.setVisible(true);
}
}

Signature
Regards,
Roland de Ruiter
___ ___
/__/ w_/ /__/
/ \ /_/ / \
trung pham dinh - 27 Apr 2005 14:09 GMT
I also have the same problem!.
Thanks for help.
And more...