Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2005

Tip: Looking for answers? Try searching our database.

using JOptionPane's error icon

Thread view: 
hkongogo@gmail.com - 27 Apr 2005 05:37 GMT
I'm writing my own error msg dialog and want to use the JOptionPane's
error icon. Pls help
Aki \ - 27 Apr 2005 08:02 GMT
> 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

Roland - 27 Apr 2005 10:34 GMT
> 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...


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.