|
Groovy Documentation | |||||||
| FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JLabel
javax.swing.table.DefaultTableCellRenderer
com.wordpress.tipsforjava.swing.table.IconTableCellRenderer
public class IconTableCellRenderer extends DefaultTableCellRenderer
The package-private class javax.swing.JTable.IconRenderer, which is the default renderer for columns of class Icon and ImageIcon, is known to give rise to a ClassCastException when attempting to render an Icon whose implementation of paintIcon(Component c, Graphics g, int x, int y) requires a cast of its first parameter to a specific subclass of Component. Many icons obtained from standard JDK classes trigger this ClassCastException.
IconTableCellRenderer addresses this issue in the following manner:
Extends DefaultTableCellRenderer
| Nested Class Summary | |
|---|---|
class |
IconTableCellRenderer.XIcon
The default icon used if none is supplied. |
| Field Summary | |
|---|---|
static AbstractButton |
button
|
Icon |
defaultIcon
|
| Fields inherited from class DefaultTableCellRenderer | |
|---|---|
| CENTER, TOP, LEFT, BOTTOM, RIGHT, NORTH, NORTH_EAST, EAST, SOUTH_EAST, SOUTH, SOUTH_WEST, WEST, NORTH_WEST, HORIZONTAL, VERTICAL, LEADING, TRAILING, NEXT, PREVIOUS, WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_IN_FOCUSED_WINDOW, UNDEFINED_CONDITION, TOOL_TIP_TEXT_KEY, TOP_ALIGNMENT, CENTER_ALIGNMENT, BOTTOM_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, WIDTH, HEIGHT, PROPERTIES, SOMEBITS, FRAMEBITS, ALLBITS, ERROR, ABORT |
| Fields inherited from class JLabel | |
|---|---|
| CENTER, TOP, LEFT, BOTTOM, RIGHT, NORTH, NORTH_EAST, EAST, SOUTH_EAST, SOUTH, SOUTH_WEST, WEST, NORTH_WEST, HORIZONTAL, VERTICAL, LEADING, TRAILING, NEXT, PREVIOUS, WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_IN_FOCUSED_WINDOW, UNDEFINED_CONDITION, TOOL_TIP_TEXT_KEY, TOP_ALIGNMENT, CENTER_ALIGNMENT, BOTTOM_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, WIDTH, HEIGHT, PROPERTIES, SOMEBITS, FRAMEBITS, ALLBITS, ERROR, ABORT |
| Constructor Summary | |
IconTableCellRenderer()
Constructs an IconTableCellRenderer which will use a crossed rectangle as default icon |
|
IconTableCellRenderer(Icon defaultIcon)
Constructs an IconTableCellRenderer which will use the supplied default icon, which must be an icon that is capable of being painted to any JComponent. |
|
| Method Summary | |
|---|---|
private void
|
createIcon(Icon icon, JComponent component)
Paints the icon to a BufferedImage for use as the renderer's Icon. |
private Color
|
getCorrectBackground(JTable table, boolean isSelected)
Obtains the correct background as per the selection status |
Component
|
getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
@see DefaultTableCellRenderer#getTableCellRendererComponent(JTable, Object, boolean, boolean, int, int) |
static void
|
setRowHeightsForIcons(JTable table)
|
| Field Detail |
|---|
static AbstractButton button
Icon defaultIcon
| Constructor Detail |
|---|
public IconTableCellRenderer()
public IconTableCellRenderer(Icon defaultIcon)
| Method Detail |
|---|
private void createIcon(Icon icon, JComponent component)
table - the JTablerow - row numbericon - the icon to be paintedcomponent - the component it represents
private Color getCorrectBackground(JTable table, boolean isSelected)
table - the JTableisSelected - selection status
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
public static void setRowHeightsForIcons(JTable table)
Groovy Documentation