Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
563 views
in Technique[技术] by (71.8m points)

swing - Default action button icons in Java

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...