Java Tips Weblog

  • Blog Stats

    • 2,076,564 hits
  • Categories

  • Archives

  • Advertisements

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

See Also

Toggle Button Icons

Related Reading

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


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: