23

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.

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
FazJaxton
  • 7,544
  • 6
  • 26
  • 32

4 Answers4

21

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)

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
Leif Gruenwoldt
  • 13,561
  • 5
  • 60
  • 64
  • 2
    a useful link [http://en-human-begin.blogspot.com/2007/11/javas-icons-by-default.html](http://en-human-begin.blogspot.com/2007/11/javas-icons-by-default.html) – Ehcnalb Jun 22 '18 at 13:17
14

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

Suma
  • 33,181
  • 16
  • 123
  • 191
camickr
  • 321,443
  • 19
  • 166
  • 288
  • 1
    These look good. It looks like I'm going to have to bundle graphics, and this is a good default. Thanks! – FazJaxton Feb 27 '12 at 15:30
  • 9
    http://www.oracle.com/technetwork/java/repository-140393.html direct link, to avoid Oracles annoying policy against deep linking. – Andrew Mackenzie Feb 23 '13 at 12:26
8

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I see that it's using file icons from the platform, but I don't see it using any icons for open, save, etc. Am I just missing it? e.g. It looks like the openFile button is just labeled "Open". Thanks. – FazJaxton Feb 27 '12 at 15:29
3

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"

Solomon Ucko
  • 5,724
  • 3
  • 24
  • 45
duffymo
  • 305,152
  • 44
  • 369
  • 561
  • @RayHulha: This answer is over two years older than [Leif](http://stackoverflow.com/users/52176/leif-gruenwoldt)'s. No one else suggested alternative icons. – Mr. Polywhirl Nov 18 '15 at 03:43
  • The icons from Leif's answer existed in 2012 as well. Duffymo just didn't have his facts straight. – Ray Hulha Nov 18 '15 at 15:02