Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default action button icons in Java

Tags:

java

icons

swing

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.

like image 981
FazJaxton Avatar asked Feb 21 '12 00:02

FazJaxton


People also ask

How do you make an icon button in Java?

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);

What are icons in Java?

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.

What is a JButton in Java?

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.

How many types of buttons are there in Java?

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.


4 Answers

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)

like image 159
Leif Gruenwoldt Avatar answered Oct 23 '22 12:10

Leif Gruenwoldt


Java Look and Feel Graphics Repository has a few icons you might be able to use.

like image 45
camickr Avatar answered Oct 23 '22 14:10

camickr


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.

like image 8
trashgod Avatar answered Oct 23 '22 12:10

trashgod


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"

like image 3
duffymo Avatar answered Oct 23 '22 14:10

duffymo