Consider using Unicode characters, instead of images. For gear, try using "\u2699"
, "\u26ed"
, or "\u26ee"
. For arrows, there are entire blocks in Unicode: Arrows; Supplemental Arrows-A, -B, and -C; and Miscellaneous Symbols and Arrows. There are many symbol blocks, like Miscellaneous Symbols, Dingbats, Geometric Shapes, and Miscellaneous Symbols and Pictographs. A nice benefit of using characters is that they scale quite well.
If you must have the JOptionPane icons, you can retrieve them using their corresponding defaults keys:
import java.awt.*;
import javax.swing.*;
public class JOptionPaneIconDisplayer {
static void show() {
Icon info = UIManager.getIcon("OptionPane.informationIcon");
Icon warning = UIManager.getIcon("OptionPane.warningIcon");
Icon error = UIManager.getIcon("OptionPane.errorIcon");
Icon question = UIManager.getIcon("OptionPane.questionIcon");
JPanel panel = new JPanel(new GridLayout(1, 0, 12, 12));
panel.add(new JLabel(info));
panel.add(new JLabel(warning));
panel.add(new JLabel(error));
panel.add(new JLabel(question));
panel.setBorder(BorderFactory.createEmptyBorder(24, 24, 24, 24));
JFrame frame = new JFrame("JOptionPane Icons");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(() -> show());
}
}
Attempting to read the icons directly from a classpath resource is not a good idea, as their names and locations may change from one Java release to the next.