Icon reference

Is there any way to reference the icons from JOptionPane from another class?
[83 byte] By [Valerianoa] at [2007-11-26 22:10:48]
# 1

"You can use:

javax.swing.UIManager.getIcon("OptionPane.informationIcon");

to access the JOptionPane icons. Depending upon which L&F you're using, you may get different versions of the icon.

Some other icons are:

1. OptionPane.errorIcon

2. OptionPane.informationIcon

3. OptionPane.warningIcon

4. OptionPane.questionIcon

Here's a sample applet:

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class Icon extends JApplet

{

public void init()

{

Container content = getContentPane();

JLabel label = new JLabel(javax.swing.UIManager.getIcon("OptionPane.informationIcon"));

content.add(label, BorderLayout.CENTER);

}

}

Hope this helps!!"

Quoted from:

http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=1&t=000121

Nethera at 2007-7-10 10:58:37 > top of Java-index,Java Essentials,Java Programming...
# 2

import javax.swing.*;

public class IconExample implements Runnable {

public void run() {

String[] names = {"error", "information", "question", "warning"};

JPanel p = new JPanel();

for(String name : names) {

Icon icon = UIManager.getIcon("OptionPane." + name + "Icon");

p.add(new JLabel(name, icon, SwingConstants.RIGHT));

}

JFrame f = new JFrame("IconExample");

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.getContentPane().add(p);

f.pack();

f.setLocationRelativeTo(null);

f.setVisible(true);

}

public static void main(String[] args) {

SwingUtilities.invokeLater(new IconExample());

}

}

DrLaszloJamfa at 2007-7-10 10:58:37 > top of Java-index,Java Essentials,Java Programming...
# 3
Thanks a lot guys.That's exactly what I was looking for.=)
Valerianoa at 2007-7-10 10:58:37 > top of Java-index,Java Essentials,Java Programming...