Is there a set of default action icons available in the Swing application framework?
For instance, instead of making a button that says "Save," I'd like the standard picture of a floppy disk without having to specify an image myself. For "Open", I'd like the standard picture of a file folder. It would be great if these adapted to the look and feel, but I'd take Swing defaults.
I'm thinking of something like:
new JButton(new ImageIcon(DEFAULT_OPEN_ICON));
I have found lots of resources about changing the look and feel, but nothing about icons either built into Java or dug out of the native system.
To add icon to a button, use the Icon class, which will allow you to add an image to the button. Icon icon = new ImageIcon("E:\editicon. PNG"); JButton button7 = new JButton(icon);
Icon is small fixed size picture, typically used to decorate components. ImageIcon is an implementation of the Icon interface that paints icons from images. Images can be created from a URL, filename, or byte array.
The class JButton is an implementation of a push button. This component has a label and generates an event when pressed. It can also have an Image.
Thus, all buttons share a set of common traits. Swing defines four types of buttons: JButton, JToggleButton, JCheckBox, and JRadioButton. All are subclasses of the AbstractButton class, which extends JComponent.
The javax.swing.UIManager#getIcon method provides access to several default system icons. The trick is knowing what String
to provide. Here are a some examples:
UIManager.getIcon("FileView.directoryIcon");
UIManager.getIcon("FileView.fileIcon");
UIManager.getIcon("FileView.computerIcon");
UIManager.getIcon("FileView.hardDriveIcon");
UIManager.getIcon("FileView.floppyDriveIcon");
UIManager.getIcon("FileChooser.newFolderIcon");
UIManager.getIcon("FileChooser.upFolderIcon");
UIManager.getIcon("FileChooser.homeFolderIcon");
UIManager.getIcon("FileChooser.detailsViewIcon");
UIManager.getIcon("FileChooser.listViewIcon");
Source @ Oracle® Community Spaces. Original (cached)
Java Look and Feel Graphics Repository has a few icons you might be able to use.
FileSystemView
has some useful platform-dependent icons; FileBrowser
is an example.
Addendum: The result depends on the platform and the parameter that is passed to getSystemIcon()
. You might also search among the UIManager Defaults by value type Icon
for a given Look & Feel. I'd also browse various open source icon sets. Because not all meanings are obvious, be sure to apply a tooltip and use familiar grouping.
No built in icons in the Java SDK, but they should be easy enough to find:
The Java™ Tutorials: How to Use Icons
Google Image search: "jquery ui button icons"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With