| Modifier and Type | Class and Description |
|---|---|
| pack-priv class | JTreeTable.
A DefaultTreeCellRenderer which can optionally skip drawing all icons. |
| pack-priv class | JTreeTable.
ListToTreeSelectionModelWrapper extends DefaultTreeSelectionModel to listen for changes in the ListSelectionModel it maintains. |
| public class | JTreeTable.
An editor that can be used to edit the tree column. |
| public class | JTreeTable.
A TreeCellRenderer that displays a JTree. |
| pack-priv static class | JTreeTable.
Component used by TreeTableCellEditor. |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| protected JTreeTable. | tree
A subclass of JTree. |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | editCellAt(int row, int column, EventObject e)
Overrides javax. Overridden to invoke repaint for the particular location if the column contains the tree. |
| public int | |
| public boolean | |
| public boolean | |
| public JTree | |
| public boolean | |
| private int | |
| public void | |
| public void | setRowHeight(int rowHeight)
Overrides javax. Overridden to pass the new rowHeight to the tree. |
| public void | |
| public void | |
| public void | |
| public void | sizeColumnsToFit(int resizingColumn)
Overrides javax. This is overridden to invoke supers implementation, and then, if the receiver is editing a Tree column, the editors bounds is reset. |
| public void | updateUI()
Overrides javax. Overridden to message super and forward the method to the tree. |
| showsIcons | back to summary |
|---|---|
| private boolean showsIcons | |
| tree | back to summary |
|---|---|
| protected JTreeTable. A subclass of JTree. | |
| treeEditable | back to summary |
|---|---|
| private boolean treeEditable | |
| JTreeTable | back to summary |
|---|---|
| public JTreeTable(TreeTableModel treeTableModel) | |
| editCellAt | back to summary |
|---|---|
| public boolean editCellAt(int row, int column, EventObject e) Overrides javax. Overridden to invoke repaint for the particular location if the column contains the tree. This is done as the tree editor does not fill the bounds of the cell, we need the renderer to paint the tree in the background, and then draw the editor over it. | |
| getEditingRow | back to summary |
|---|---|
| public int getEditingRow() Overrides javax. Workaround for BasicTableUI anomaly. Make sure the UI never tries to resize the editor. The UI currently uses different techniques to paint the renderers and editors and overriding setBounds() below is not the right thing to do for an editor. Returning -1 for the editing row in this case, ensures the editor is never painted. | |
| getShowsIcons | back to summary |
|---|---|
| public boolean getShowsIcons() | |
| getShowsRootHandles | back to summary |
|---|---|
| public boolean getShowsRootHandles() | |
| getTree | back to summary |
|---|---|
| public JTree getTree() Returns the tree that is being shared between the model. | |
| getTreeEditable | back to summary |
|---|---|
| public boolean getTreeEditable() | |
| realEditingRow | back to summary |
|---|---|
| private int realEditingRow() Returns the actual row that is editing as | |
| setRootVisible | back to summary |
|---|---|
| public void setRootVisible(boolean visible) | |
| setRowHeight | back to summary |
|---|---|
| public void setRowHeight(int rowHeight) Overrides javax. Overridden to pass the new rowHeight to the tree. | |
| setShowsIcons | back to summary |
|---|---|
| public void setShowsIcons(boolean show) | |
| setShowsRootHandles | back to summary |
|---|---|
| public void setShowsRootHandles(boolean newValue) | |
| setTreeEditable | back to summary |
|---|---|
| public void setTreeEditable(boolean editable) | |
| sizeColumnsToFit | back to summary |
|---|---|
| public void sizeColumnsToFit(int resizingColumn) Overrides javax. This is overridden to invoke supers implementation, and then,
if the receiver is editing a Tree column, the editors bounds is
reset. The reason we have to do this is because JTable doesn't
think the table is being edited, as | |
| updateUI | back to summary |
|---|---|
| public void updateUI() Overrides javax. Overridden to message super and forward the method to the tree. Since the tree is not actually in the component hieachy it will never receive this unless we forward it in this manner. | |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public Icon | getClosedIcon()
Overrides javax. Returns the icon used to represent non-leaf nodes that are not expanded. |
| public Icon | getDefaultClosedIcon()
Overrides javax. Returns the default icon, for the current laf, that is used to represent non-leaf nodes that are not expanded. |
| public Icon | getDefaultLeafIcon()
Overrides javax. Returns the default icon, for the current laf, that is used to represent leaf nodes. |
| public Icon | getDefaultOpenIcon()
Overrides javax. Returns the default icon, for the current laf, that is used to represent non-leaf nodes that are expanded. |
| public Icon | getLeafIcon()
Overrides javax. Returns the icon used to represent leaf nodes. |
| public Icon | getOpenIcon()
Overrides javax. Returns the icon used to represent non-leaf nodes that are expanded. |
| JTreeTableCellRenderer | back to summary |
|---|---|
| pack-priv JTreeTableCellRenderer() | |
| getClosedIcon | back to summary |
|---|---|
| public Icon getClosedIcon() Overrides javax. Doc from javax. Returns the icon used to represent non-leaf nodes that are not expanded. | |
| getDefaultClosedIcon | back to summary |
|---|---|
| public Icon getDefaultClosedIcon() Overrides javax. Doc from javax. Returns the default icon, for the current laf, that is used to represent non-leaf nodes that are not expanded. | |
| getDefaultLeafIcon | back to summary |
|---|---|
| public Icon getDefaultLeafIcon() Overrides javax. Doc from javax. Returns the default icon, for the current laf, that is used to represent leaf nodes. | |
| getDefaultOpenIcon | back to summary |
|---|---|
| public Icon getDefaultOpenIcon() Overrides javax. Doc from javax. Returns the default icon, for the current laf, that is used to represent non-leaf nodes that are expanded. | |
| getLeafIcon | back to summary |
|---|---|
| public Icon getLeafIcon() Overrides javax. Doc from javax. Returns the icon used to represent leaf nodes. | |
| getOpenIcon | back to summary |
|---|---|
| public Icon getOpenIcon() Overrides javax. Doc from javax. Returns the icon used to represent non-leaf nodes that are expanded. | |
| Modifier and Type | Class and Description |
|---|---|
| pack-priv class | JTreeTable.
Class responsible for calling updateSelectedPathsFromSelectedRows when the selection of the list changse. |
| Modifier and Type | Field and Description |
|---|---|
| protected boolean | updatingListSelectionModel
Set to true when we are updating the ListSelectionModel. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected ListSelectionListener | |
| pack-priv ListSelectionModel | |
| public void | resetRowSelection()
Overrides javax. Implements javax. This is overridden to set |
| protected void | updateSelectedPathsFromSelectedRows()
If |
| updatingListSelectionModel | back to summary |
|---|---|
| protected boolean updatingListSelectionModel Set to true when we are updating the ListSelectionModel. | |
| ListToTreeSelectionModelWrapper | back to summary |
|---|---|
| public ListToTreeSelectionModelWrapper() | |
| createListSelectionListener | back to summary |
|---|---|
| protected ListSelectionListener createListSelectionListener() Creates and returns an instance of ListSelectionHandler. | |
| getListSelectionModel | back to summary |
|---|---|
| pack-priv ListSelectionModel getListSelectionModel() Returns the list selection model. ListToTreeSelectionModelWrapper listens for changes to this model and updates the selected paths accordingly. | |
| resetRowSelection | back to summary |
|---|---|
| public void resetRowSelection() Overrides javax. Implements javax. This is overridden to set | |
| updateSelectedPathsFromSelectedRows | back to summary |
|---|---|
| protected void updateSelectedPathsFromSelectedRows() If | |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | valueChanged(ListSelectionEvent e)
Implements javax. Called whenever the value of the selection changes. |
| ListSelectionHandler | back to summary |
|---|---|
| pack-priv ListSelectionHandler() | |
| valueChanged | back to summary |
|---|---|
| public void valueChanged(ListSelectionEvent e) Implements javax. Doc from javax. Called whenever the value of the selection changes. | |
To support editing of the tree column we can not make the tree editable. The reason this doesn't work is that you can not use the same component for editing and rendering. The table may have the need to paint cells, while a cell is being edited. If the same component were used for the rendering and editing the component would be moved around, and the contents would change. When editing, this is undesirable, the contents of the text field must stay the same, including the caret blinking, and selections persisting. For this reason the editing is done via a TableCellEditor.
Another interesting thing to be aware of is how tree positions
its render and editor. The render/editor is responsible for drawing the
icon indicating the type of node (leaf, branch...). The tree is
responsible for drawing any other indicators, perhaps an additional
+/- sign, or lines connecting the various nodes. So, the renderer
is positioned based on depth. On the other hand, table always makes
its editor fill the contents of the cell. To get the allusion
that the table cell editor is part of the tree, we don't want the
table cell editor to fill the cell bounds. We want it to be placed
in the same manner as tree places it editor, and have table message
the tree to paint any decorations the tree wants. Then, we would
only have to worry about the editing part. The approach taken
here is to determine where tree would place the editor, and to override
the reshape method in the JTextField component to
nudge the textfield to the location tree would place it. Since
JTreeTable will paint the tree behind the editor everything should
just work. So, that is what we are doing here. Determining of
the icon position will only work if the TreeCellRenderer is
an instance of DefaultTreeCellRenderer. If you need custom
TreeCellRenderers, that don't descend from DefaultTreeCellRenderer,
and you want to support editing in JTreeTable, you will have
to do something similar.
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Component | getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int r, int c)
Overrides javax. Implements javax. Overridden to determine an offset that tree would place the editor at. |
| public boolean | isCellEditable(EventObject e)
Overrides javax. Implements javax. This is overridden to forward the event to the tree. |
| TreeTableCellEditor | back to summary |
|---|---|
| public TreeTableCellEditor() | |
| getTableCellEditorComponent | back to summary |
|---|---|
| public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int r, int c) Overrides javax. Implements javax. Overridden to determine an offset that tree would place the
editor at. The offset is determined from the
The offset is then set on the TreeTableTextField component created in the constructor, and returned. | |
| isCellEditable | back to summary |
|---|---|
| public boolean isCellEditable(EventObject e) Overrides javax. Implements javax. This is overridden to forward the event to the tree. This will return true if the click count >= 3, or the event is null. | |
| Modifier and Type | Field and Description |
|---|---|
| protected Border | highlightBorder
Border to draw around the tree, if this is non-null, it will be painted. |
| protected int | visibleRow
Last table/tree row asked to renderer. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Component | getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
Implements javax. TreeCellRenderer method. |
| public void | paint(Graphics g)
Overrides javax. Sublcassed to translate the graphics such that the last visible row will be drawn at 0,0. |
| public void | setBounds(int x, int y, int w, int h)
Overrides java. This is overridden to set the height to match that of the JTable. |
| public void | setRowHeight(int rowHeight)
Overrides javax. Sets the row height of the tree, and forwards the row height to the table. |
| public void | updateUI()
Overrides javax. updateUI is overridden to set the colors of the Tree's renderer to match that of the table. |
| highlightBorder | back to summary |
|---|---|
| protected Border highlightBorder Border to draw around the tree, if this is non-null, it will be painted. | |
| visibleRow | back to summary |
|---|---|
| protected int visibleRow Last table/tree row asked to renderer. | |
| TreeTableCellRenderer | back to summary |
|---|---|
| public TreeTableCellRenderer(TreeModel model) | |
| getTableCellRendererComponent | back to summary |
|---|---|
| public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) Implements javax. TreeCellRenderer method. Overridden to update the visible row. | |
| paint | back to summary |
|---|---|
| public void paint(Graphics g) Overrides javax. Sublcassed to translate the graphics such that the last visible row will be drawn at 0,0. | |
| setBounds | back to summary |
|---|---|
| public void setBounds(int x, int y, int w, int h) Overrides java. This is overridden to set the height to match that of the JTable. | |
| setRowHeight | back to summary |
|---|---|
| public void setRowHeight(int rowHeight) Overrides javax. Sets the row height of the tree, and forwards the row height to the table. | |
| updateUI | back to summary |
|---|---|
| public void updateUI() Overrides javax. updateUI is overridden to set the colors of the Tree's renderer to match that of the table. | |
reshape method, and to ALWAYS
make the x location be offset.
| Modifier and Type | Field and Description |
|---|---|
| public int |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | setBounds(int x, int y, int w, int h)
Overrides java. Moves and resizes this component. |
| offset | back to summary |
|---|---|
| public int offset | |
| TreeTableTextField | back to summary |
|---|---|
| pack-priv TreeTableTextField() | |
| setBounds | back to summary |
|---|---|
| public void setBounds(int x, int y, int w, int h) Overrides java. Doc from java. Moves and resizes this component. The new location of the top-left
corner is specified by This method changes layout-related information, and therefore, invalidates the component hierarchy. | |