Java Tips Weblog

  • Blog Stats

    • 1,102,320 hits
  • Categories

  • Archives

Dual Icon

Posted by Darryl Burke on March 22, 2009

Many Swing components accommodate an icon. What if you would like to display more than one icon on the same component, or show a custom icon on a component like JCheckBox or JRadioButton, in addition to the icon that the Look and Feel displays by default?

DualIcon to the rescue! This simple class facilitates making one icon from two. The composite icon can be applied to the component using setIcon.

DualIcon exposes two public constructors, one of which allows flexibility in the relative placement of the icons and the gap between them. The parameters for horizontal and vertical position are inherited from the familiar SwingConstants interface, which is implemented by the class.

Possible uses for DualIcon include displaying two icons in a JOptionPane, possibly a company logo alongside the usual icon, or adding a custom icon to a JCheckBox or JRadioButton. A set of classes that inherit from DualIcon to provide specialized functionality for the latter purpose is the subject of a later blog posting.

Get The Code

DualIcon.java

See Also

Toggle Button Icons

Related Reading

The Java™ Tutorials: How to Use Icons
Java API: javax.swing.Icon
Java API: javax.swing.SwingConstants

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 88 other followers

%d bloggers like this: