public class CompositeIcon
extends java.lang.Object
implements javax.swing.Icon
CompositeIcon is an Icon implementation which draws two icons with a
specified relative position from the constant class SwingConstants
:
SwingConstants.LEFT
, SwingConstants.RIGHT
,
SwingConstants.TOP
, SwingConstants.BOTTOM
specify how icon1 is drawn relative to icon2
SwingConstants.CENTER
: icon1 is drawn first, icon2 is drawn over it
and with horizontal and vertical orientations within the alloted space
It's useful with VTextIcon when you want an icon with your text: if icon1 is the graphic icon and icon2 is the VTextIcon, you get a similar effect to a JLabel with a graphic icon and text.
The following section is take from the web page of Lee Ann Rucker:
To create tabs with vertical text, first create a JTabbedPane with LEFT or RIGHT tabs:
JTabbedPane panel = new JTabbedPane(LEFT);
Then create a VTextIcon for that panel. We'll use the default orientation here:
VTextIcon textIcon = new VTextIcon(panel, "Mac OS X");
The test application uses one of the FileView icons, but any icon will do:
Icon graphicIcon = UIManager.getIcon("FileView.computerIcon");
Now use a CompositeIcon to combine them:
CompositeIcon icon = new CompositeIcon(graphicIcon, textIcon);
Finally, create the tab, passing in "null" for the title, the CompositeIcon, and the Component to be displayed when this tab is active (makePane is a placeholder in the test application):
panel.addTab(null, icon, makePane());
If you only want to display text, just use the VTextIcon in addTab:
panel.addTab(null, textIcon, makePane());
ATTENTION: This class has been taken from the tutorial web pages from O'Reilly called macdevCenter.com. The original author and creator of this class was Lee Ann Rucker. Currently you will find the web page under http://www.oreillynet.com/pub/a/mac/2002/03/22/vertical_text.html. For further information you should refer to this page.
Constructor and Description |
---|
CompositeIcon(javax.swing.Icon icon1,
javax.swing.Icon icon2)
Create a CompositeIcon from the specified Icons,
using the default relative position (icon1 above icon2)
and orientations (centered horizontally and vertically)
|
CompositeIcon(javax.swing.Icon icon1,
javax.swing.Icon icon2,
int position)
Create a CompositeIcon from the specified Icons,
using the specified relative position
and default orientations (centered horizontally and vertically)
|
CompositeIcon(javax.swing.Icon icon1,
javax.swing.Icon icon2,
int position,
int horizontalOrientation,
int verticalOrientation)
Create a CompositeIcon from the specified Icons,
using the specified relative position
and orientations
|
Modifier and Type | Method and Description |
---|---|
int |
getIconHeight()
Returns the icon's height.
|
int |
getIconWidth()
Returns the icon's width.
|
void |
paintIcon(java.awt.Component component_,
java.awt.Graphics graphics_,
int x_,
int y_)
Draw the icon at the specified location.
|
public CompositeIcon(javax.swing.Icon icon1, javax.swing.Icon icon2)
icon1
- icon2
- public CompositeIcon(javax.swing.Icon icon1, javax.swing.Icon icon2, int position)
icon1
- icon2
- position
- public CompositeIcon(javax.swing.Icon icon1, javax.swing.Icon icon2, int position, int horizontalOrientation, int verticalOrientation)
icon1
- icon2
- position
- Is the position from the constant class SwingConstant
.horizontalOrientation
- verticalOrientation
- public void paintIcon(java.awt.Component component_, java.awt.Graphics graphics_, int x_, int y_)
paintIcon
in interface javax.swing.Icon
component_
- graphics_
- x_
- y_
- paintIcon(Component, Graphics, int, int)
public int getIconWidth()
getIconWidth
in interface javax.swing.Icon
public int getIconHeight()
getIconHeight
in interface javax.swing.Icon
14-September-2016 18:23 Deutsches Elektronen-Synchrotron DESY in der Helmholtz-Gemeinschaft