|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.table.JTableHeader com.jidesoft.grid.DraggingTableHeader com.jidesoft.grid.CellStyleTableHeader com.jidesoft.grid.SortableTableHeader com.jidesoft.grid.EditableTableHeader
public class EditableTableHeader
As the name indicates, EditableTableHeader
is an editable JTableHeader
.
EditableTableHeader
.
JTable table = new JTable(tableModel);
EditableTableHeader header = new EditableTableHeader(table.getColumnModel());
table.setTableHeader(header);
Once EditableTableHeader
is installed on the table, user can double click on the table header to start
editing. Pressing ENTER will commit editing or pressing ESCAPE to cancel editing.
By default, we will use TextFieldCellEditor
as the cell editor. You can either override createDefaultEditor()
method or call setDefaultEditor(javax.swing.table.TableCellEditor)
to set your own
cell editor. Please note, if you use your own cell editor, you may need to register ENTER and ESCAPE key to allow
stop or cancel cell editing.
By default, all table columns will be editable. The same cell editor will be used for all columns. If you want only
some of the columns editable and each one has its own cell editor, you just need to implement EditableColumnTableModel
interface in your table model. EditableColumnTableModel
has
methods to let you decide which column is editable and what cell editor to be used.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.table.JTableHeader |
---|
JTableHeader.AccessibleJTableHeader |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
protected TableCellEditor |
_cellEditor
|
protected TableCellEditor |
_defaultEditor
|
protected int |
_editingColumn
|
protected Component |
_editorComp
|
int |
HEADER_ROW
|
Fields inherited from class com.jidesoft.grid.SortableTableHeader |
---|
PROPERTY_SHOW_SORT_ARROW |
Fields inherited from class com.jidesoft.grid.CellStyleTableHeader |
---|
_cellStyleList |
Fields inherited from class com.jidesoft.grid.DraggingTableHeader |
---|
PROPERTY_DRAGGED_COLUMN, PROPERTY_DRAGGED_DISTANCE, PROPERTY_RESIZING_COLUMN |
Fields inherited from class javax.swing.table.JTableHeader |
---|
columnModel, draggedColumn, draggedDistance, reorderingAllowed, resizingAllowed, resizingColumn, table, updateTableInRealTime |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
EditableTableHeader(JTable table)
The constructor that takes JTable |
|
EditableTableHeader(TableColumnModel columnModel)
Creates an EditableTableHeader . |
Method Summary | |
---|---|
void |
cancelEditing()
Cancels any existing cell editing. |
protected TableCellEditor |
createDefaultEditor()
Creates a default header cell editor to be used. |
protected void |
customizeEditorComponent(Component component,
int rowIndex,
int columnIndex)
Customizes the editor component based on the header style. |
boolean |
editCellAt(int columnIndex)
Edits the column at the specified column index. |
boolean |
editCellAt(int columnIndex,
EventObject e)
Edits the column at the specified column index. |
void |
editingCanceled(ChangeEvent e)
|
void |
editingStopped(ChangeEvent e)
|
String |
getActualUIClassID()
Returns a string that specifies the name of the L&F class that renders this component. |
TableCellEditor |
getCellEditor()
Returns the active header cell editor, which is null if the table header is not currently editing. |
TableCellEditor |
getCellEditor(int columnIndex)
Gets the header cell editor for the specified column index. |
TableCellEditor |
getDefaultEditor()
Returns the default editor. |
int |
getEditingColumn()
Returns the index of the column that contains the cell currently being edited. |
Component |
getEditorComponent()
Returns the component that is handling the editing session. |
String |
getUIDelegateClassID()
Returns a string that specifies the name of the UIDelegate class that paints this component. |
protected boolean |
isAutoRequestFocus()
If the editor requests focus when starts editing. |
boolean |
isCellEditable(int columnIndex)
Returns true if the header cell at index is editable. |
boolean |
isClickToStartEditing()
|
boolean |
isEditing()
Returns true if a header cell is being edited. |
boolean |
isRolloverEnabled()
Checks if rollover is enabled. |
Component |
prepareEditor(TableCellEditor editor,
int columnIndex)
Prepares the editor by querying the TableColumnModel for the value and selection state of the header
cell at columnIndex . |
void |
removeEditor()
Discards the editor object and frees the real estate it used for cell rendering. |
void |
removeNotify()
Calls the unconfigureEnclosingScrollPane method. |
void |
resizeAndRepaint()
Sizes the header and marks it as needing display. |
protected void |
setCellEditor(TableCellEditor newEditor)
Sets the currently used cell editor. |
void |
setClickToStartEditing(boolean clickToStartEditing)
|
void |
setDefaultEditor(TableCellEditor defaultEditor)
Sets the default editor to be used. |
void |
setDraggedColumn(TableColumn column)
|
void |
setEditingColumn(int aColumn)
Sets the editingColumn variable. |
void |
setRolloverEnabled(boolean rolloverEnabled)
Sets rollover flag. |
void |
stopEditing()
Stops any existing cell editing. |
Methods inherited from class com.jidesoft.grid.SortableTableHeader |
---|
createSortableTableHeaderCellDecorator, createSortIcon, getSortableTableHeaderCellDecorator, isShowSortArrow, paintComponent, paintSortArrow, paintSortArrows, setShowSortArrow |
Methods inherited from class com.jidesoft.grid.DraggingTableHeader |
---|
getPreferredSize, getToolTipText, setDraggedDistance, setResizingColumn |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public final int HEADER_ROW
protected transient int _editingColumn
protected transient TableCellEditor _cellEditor
protected transient Component _editorComp
protected TableCellEditor _defaultEditor
Constructor Detail |
---|
public EditableTableHeader(JTable table)
table
- the tablepublic EditableTableHeader(TableColumnModel columnModel)
EditableTableHeader
.
columnModel
- the column model.Method Detail |
---|
public String getUIDelegateClassID()
getUIDelegateClassID
in class SortableTableHeader
public String getActualUIClassID()
SortableTableHeader
getActualUIClassID
in class SortableTableHeader
public boolean isRolloverEnabled()
public void setRolloverEnabled(boolean rolloverEnabled)
rolloverEnabled
- true or false.public void resizeAndRepaint()
revalidate
followed by
repaint
. EditableTableHeader
overrides this method to stop cell editing first.
resizeAndRepaint
in class JTableHeader
public void stopEditing()
public void cancelEditing()
protected TableCellEditor createDefaultEditor()
public void setDefaultEditor(TableCellEditor defaultEditor)
defaultEditor
- the default editorpublic TableCellEditor getDefaultEditor()
public boolean editCellAt(int columnIndex)
columnIndex
- the column index to be edited.
public void setDraggedColumn(TableColumn column)
setDraggedColumn
in class DraggingTableHeader
public boolean editCellAt(int columnIndex, EventObject e)
columnIndex
- the column index to be edited.e
- the event that triggers the editing.
protected void customizeEditorComponent(Component component, int rowIndex, int columnIndex)
component
- the editor componentrowIndex
- the row indexcolumnIndex
- the column indexpublic boolean isCellEditable(int columnIndex)
index
is editable.
Note: The column is specified in the table view's display order, and not in the TableModel
's
column order. This is an important distinction because as the user rearranges the columns in the table, the
column at a given index in the view will change. Meanwhile the user's actions never affect the model's column
ordering.
columnIndex
- the column whose value is to be queried
public TableCellEditor getCellEditor(int columnIndex)
TableModelWrapper
implement EditableColumnTableModel
interface, it will use that
interface and call EditableColumnTableModel.getColumnHeaderCellEditor(int)
to get the cell editor. If
null, we will use getDefaultEditor()
.
columnIndex
- the column index.
protected void setCellEditor(TableCellEditor newEditor)
newEditor
- the new cell editor that is using.public Component prepareEditor(TableCellEditor editor, int columnIndex)
TableColumnModel
for the value and selection state of the header
cell at columnIndex
.
Note: Throughout the table package, the internal implementations always use this method to prepare editors
so that this default behavior can be safely overridden by a subclass.
editor
- the TableCellEditor
to set upcolumnIndex
- the column of the cell to edit, where 0 is the first column
Component
being editedpublic TableCellEditor getCellEditor()
null
if the table header is not currently editing.
TableCellEditor
that does the editing, or null
if the table header is not currently
editing.getCellEditor(int)
public Component getEditorComponent()
public void setEditingColumn(int aColumn)
editingColumn
variable.
aColumn
- the column of the cell to be editedpublic int getEditingColumn()
public void removeEditor()
public boolean isEditing()
public void editingStopped(ChangeEvent e)
editingStopped
in interface CellEditorListener
public void editingCanceled(ChangeEvent e)
editingCanceled
in interface CellEditorListener
public void removeNotify()
unconfigureEnclosingScrollPane
method.
removeNotify
in class JComponent
public boolean isClickToStartEditing()
public void setClickToStartEditing(boolean clickToStartEditing)
protected boolean isAutoRequestFocus()
|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |