Package jadex.commons.gui.jtable
Class ResizeableTableHeader
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.table.JTableHeader
-
- jadex.commons.gui.jtable.ResizeableTableHeader
-
- All Implemented Interfaces:
java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.io.Serializable
,java.util.EventListener
,javax.accessibility.Accessible
,javax.swing.event.TableColumnModelListener
,javax.swing.event.TableModelListener
public class ResizeableTableHeader extends javax.swing.table.JTableHeader implements javax.swing.event.TableModelListener
This subclass ofJTableHeader
extends aJTable
with the ability to resize a column to fit all its content on double click on the right end of the column's header cell.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.table.JTableHeader
javax.swing.table.JTableHeader.AccessibleJTableHeader
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
autoResizingEnabled
If true, auto resizing of columns when the TableModel invokes a tableChanged event is enabled.protected boolean
includeHeaderWidth
If true, resizing of columns will also take the width of header cells into account.-
Fields inherited from class javax.swing.table.JTableHeader
columnModel, draggedColumn, draggedDistance, reorderingAllowed, resizingAllowed, resizingColumn, table, updateTableInRealTime
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor Description ResizeableTableHeader()
Constructs aResizeableTableHeader
with a defaultTableColumnModel
.ResizeableTableHeader(javax.swing.table.TableColumnModel cm)
Constructs aResizeableTableHeader
which is initialized withcm
as the column model.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
getAutoResizingEnabled()
Returns true if auto resizing is enabled.boolean
getIncludeHeaderWidth()
Returns true, if the header's width arevoid
resizeAllColumns()
Resizes all columns to fit all their content.void
resizeColumn(javax.swing.table.TableColumn column)
Resizes the given column to fit all its content.void
setAllColumnWidths(int preferredWidth, int minWidth, int maxWidth)
Sets preferred width, the minimum and maximum width for all columns.void
setAutoResizingEnabled(boolean autoResizingEnabled)
Sets whether columns are resized on table model events.void
setColumnWidths(javax.swing.table.TableColumn column, int preferredWidth, int minWidth, int maxWidth)
Sets preferred width, the minimum and maximum width for a given column.void
setIncludeHeaderWidth(boolean includeHeaderWidth)
Sets whether the header's width are included on calculationvoid
setTable(javax.swing.JTable table)
Sets the table associated with this header.void
tableChanged(javax.swing.event.TableModelEvent e)
Listen for table model events from tablemodel.-
Methods inherited from class javax.swing.table.JTableHeader
columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, createDefaultColumnModel, createDefaultRenderer, getAccessibleContext, getColumnModel, getDefaultRenderer, getDraggedColumn, getDraggedDistance, getHeaderRect, getPreferredSize, getReorderingAllowed, getResizingAllowed, getResizingColumn, getTable, getToolTipText, getUI, getUIClassID, getUpdateTableInRealTime, initializeLocalVars, paramString, resizeAndRepaint, setColumnModel, setDefaultRenderer, setDraggedColumn, setDraggedDistance, setReorderingAllowed, setResizingAllowed, setResizingColumn, setUI, setUpdateTableInRealTime, updateUI
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
autoResizingEnabled
protected boolean autoResizingEnabled
If true, auto resizing of columns when the TableModel invokes a tableChanged event is enabled. The default is false.
-
includeHeaderWidth
protected boolean includeHeaderWidth
If true, resizing of columns will also take the width of header cells into account. The default is false.
-
-
Constructor Detail
-
ResizeableTableHeader
public ResizeableTableHeader()
Constructs aResizeableTableHeader
with a defaultTableColumnModel
.
-
ResizeableTableHeader
public ResizeableTableHeader(javax.swing.table.TableColumnModel cm)
Constructs aResizeableTableHeader
which is initialized withcm
as the column model. Ifcm
isnull
this method will initialize the table header with a defaultTableColumnModel
.- Parameters:
cm
- the column model for the table
-
-
Method Detail
-
setTable
public void setTable(javax.swing.JTable table)
Sets the table associated with this header. Also adds a TableModelListener to the table's TableModel to allow resizing of columns if data of table changed.- Overrides:
setTable
in classjavax.swing.table.JTableHeader
- Parameters:
table
- the new table
-
setAutoResizingEnabled
public void setAutoResizingEnabled(boolean autoResizingEnabled)
Sets whether columns are resized on table model events.- Parameters:
autoResizingEnabled
- true if columns are resized automatically- See Also:
getAutoResizingEnabled()
-
getAutoResizingEnabled
public boolean getAutoResizingEnabled()
Returns true if auto resizing is enabled.- Returns:
- the
autoResizingEnabled
property - See Also:
setAutoResizingEnabled(boolean)
-
setIncludeHeaderWidth
public void setIncludeHeaderWidth(boolean includeHeaderWidth)
Sets whether the header's width are included on calculation- Parameters:
includeHeaderWidth
- true if the headers are included- See Also:
getIncludeHeaderWidth()
-
getIncludeHeaderWidth
public boolean getIncludeHeaderWidth()
Returns true, if the header's width are- Returns:
- the
setIncludeHeaderWidth
property - See Also:
setIncludeHeaderWidth(boolean)
-
resizeColumn
public void resizeColumn(javax.swing.table.TableColumn column)
Resizes the given column to fit all its content.- Parameters:
column
- TheTableColumn
to resize.
-
resizeAllColumns
public void resizeAllColumns()
Resizes all columns to fit all their content.
-
setColumnWidths
public void setColumnWidths(javax.swing.table.TableColumn column, int preferredWidth, int minWidth, int maxWidth)
Sets preferred width, the minimum and maximum width for a given column. The minimum and maximum widths are the bounds for the preferred width. If the preferred width is not in the region of minmum and maximum, it will be adjusted. Also the user cannot resize columns out of this bounds by moving the edge or double clicking it. If a width is set to -1, no change is made to this value.- Parameters:
column
- TheTableColumn
to change.preferredWidth
- The preferred width of the column.minWidth
- The minimum width of the column.maxWidth
- The maximum width of the column.- See Also:
setAllColumnWidths(int preferredWidth, int minWidth, int maxWidth)
-
setAllColumnWidths
public void setAllColumnWidths(int preferredWidth, int minWidth, int maxWidth)
Sets preferred width, the minimum and maximum width for all columns. See setColumnWidth() for further details.- Parameters:
preferredWidth
- The preferred width of the column.minWidth
- The minimum width of the column.maxWidth
- The maximum width of the column.- See Also:
setColumnWidths(javax.swing.table.TableColumn column,int preferredWidth, int minWidth, int maxWidth)
-
tableChanged
public void tableChanged(javax.swing.event.TableModelEvent e)
Listen for table model events from tablemodel. If new data is inserted, only determine the width of new cell and adjust column width, if necessary. If data is deleted or updated, callresizeAllColumns()
.- Specified by:
tableChanged
in interfacejavax.swing.event.TableModelListener
- Parameters:
e
- TheTableModelEvent
-
-