| Method from javax.swing.table.JTableHeader Detail: |
public void columnAdded(TableColumnModelEvent e) {
resizeAndRepaint();
}
Invoked when a column is added to the table column model.
Application code will not use these methods explicitly, they
are used internally by JTable. |
public int columnAtPoint(Point point) {
int x = point.x;
if (!getComponentOrientation().isLeftToRight()) {
x = getWidthInRightToLeft() - x - 1;
}
return getColumnModel().getColumnIndexAtX(x);
}
Returns the index of the column that point lies in, or -1 if it
lies out of bounds. |
public void columnMarginChanged(ChangeEvent e) {
resizeAndRepaint();
}
Invoked when a column is moved due to a margin change.
Application code will not use these methods explicitly, they
are used internally by JTable. |
public void columnMoved(TableColumnModelEvent e) {
repaint();
}
Invoked when a column is repositioned.
Application code will not use these methods explicitly, they
are used internally by JTable. |
public void columnRemoved(TableColumnModelEvent e) {
resizeAndRepaint();
}
Invoked when a column is removed from the table column model.
Application code will not use these methods explicitly, they
are used internally by JTable. |
public void columnSelectionChanged(ListSelectionEvent e) {
}
Invoked when the selection model of the TableColumnModel
is changed. This method currently has no effect (the header is not
redrawn).
Application code will not use these methods explicitly, they
are used internally by JTable. |
protected TableColumnModel createDefaultColumnModel() {
return new DefaultTableColumnModel();
}
Returns the default column model object which is
a DefaultTableColumnModel. A subclass can override this
method to return a different column model object |
protected TableCellRenderer createDefaultRenderer() {
return new DefaultTableCellHeaderRenderer();
}
Returns a default renderer to be used when no header renderer
is defined by a TableColumn. |
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJTableHeader();
}
return accessibleContext;
}
Gets the AccessibleContext associated with this JTableHeader.
For JTableHeaders, the AccessibleContext takes the form of an
AccessibleJTableHeader.
A new AccessibleJTableHeader instance is created if necessary. |
public TableColumnModel getColumnModel() {
return columnModel;
}
Returns the TableColumnModel that contains all column information
of this table header. |
public TableCellRenderer getDefaultRenderer() {
return defaultRenderer;
}
Returns the default renderer used when no headerRenderer
is defined by a TableColumn. |
public TableColumn getDraggedColumn() {
return draggedColumn;
}
Returns the the dragged column, if and only if, a drag is in
process, otherwise returns null. |
public int getDraggedDistance() {
return draggedDistance;
}
Returns the column's horizontal distance from its original
position, if and only if, a drag is in process. Otherwise, the
the return value is meaningless. |
public Rectangle getHeaderRect(int column) {
Rectangle r = new Rectangle();
TableColumnModel cm = getColumnModel();
r.height = getHeight();
if (column < 0) {
// x = width = 0;
if( !getComponentOrientation().isLeftToRight() ) {
r.x = getWidthInRightToLeft();
}
}
else if (column >= cm.getColumnCount()) {
if( getComponentOrientation().isLeftToRight() ) {
r.x = getWidth();
}
}
else {
for(int i = 0; i < column; i++) {
r.x += cm.getColumn(i).getWidth();
}
if( !getComponentOrientation().isLeftToRight() ) {
r.x = getWidthInRightToLeft() - r.x - cm.getColumn(column).getWidth();
}
r.width = cm.getColumn(column).getWidth();
}
return r;
}
Returns the rectangle containing the header tile at column.
When the column parameter is out of bounds this method uses the
same conventions as the JTable method getCellRect. |
public boolean getReorderingAllowed() {
return reorderingAllowed;
}
Returns true if the user is allowed to rearrange columns by
dragging their headers, false otherwise. The default is true. You can
rearrange columns programmatically regardless of this setting. |
public boolean getResizingAllowed() {
return resizingAllowed;
}
Returns true if the user is allowed to resize columns by dragging
between their headers, false otherwise. The default is true. You can
resize columns programmatically regardless of this setting. |
public TableColumn getResizingColumn() {
return resizingColumn;
}
Returns the resizing column. If no column is being
resized this method returns null. |
public JTable getTable() {
return table;
}
Returns the table associated with this header. |
public String getToolTipText(MouseEvent event) {
String tip = null;
Point p = event.getPoint();
int column;
// Locate the renderer under the event location
if ((column = columnAtPoint(p)) != -1) {
TableColumn aColumn = columnModel.getColumn(column);
TableCellRenderer renderer = aColumn.getHeaderRenderer();
if (renderer == null) {
renderer = defaultRenderer;
}
Component component = renderer.getTableCellRendererComponent(
getTable(), aColumn.getHeaderValue(), false, false,
-1, column);
// Now have to see if the component is a JComponent before
// getting the tip
if (component instanceof JComponent) {
// Convert the event to the renderer's coordinate system
MouseEvent newEvent;
Rectangle cellRect = getHeaderRect(column);
p.translate(-cellRect.x, -cellRect.y);
newEvent = new MouseEvent(component, event.getID(),
event.getWhen(), event.getModifiers(),
p.x, p.y, event.getXOnScreen(), event.getYOnScreen(),
event.getClickCount(),
event.isPopupTrigger(), MouseEvent.NOBUTTON);
tip = ((JComponent)component).getToolTipText(newEvent);
}
}
// No tip from the renderer get our own tip
if (tip == null)
tip = getToolTipText();
return tip;
}
Allows the renderer's tips to be used if there is text set. |
public TableHeaderUI getUI() {
return (TableHeaderUI)ui;
}
Returns the look and feel (L&F) object that renders this component. |
public String getUIClassID() {
return uiClassID;
}
Returns the suffix used to construct the name of the look and feel
(L&F) class used to render this component. |
public boolean getUpdateTableInRealTime() {
return updateTableInRealTime;
}
Obsolete as of Java 2 platform v1.3. Real time repaints, in response to
column dragging or resizing, are now unconditional. |
protected void initializeLocalVars() {
setOpaque(true);
table = null;
reorderingAllowed = true;
resizingAllowed = true;
draggedColumn = null;
draggedDistance = 0;
resizingColumn = null;
updateTableInRealTime = true;
// I'm registered to do tool tips so we can draw tips for the
// renderers
ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
toolTipManager.registerComponent(this);
setDefaultRenderer(createDefaultRenderer());
}
Initializes the local variables and properties with default values.
Used by the constructor methods. |
protected String paramString() {
String reorderingAllowedString = (reorderingAllowed ?
"true" : "false");
String resizingAllowedString = (resizingAllowed ?
"true" : "false");
String updateTableInRealTimeString = (updateTableInRealTime ?
"true" : "false");
return super.paramString() +
",draggedDistance=" + draggedDistance +
",reorderingAllowed=" + reorderingAllowedString +
",resizingAllowed=" + resizingAllowedString +
",updateTableInRealTime=" + updateTableInRealTimeString;
}
|
public void resizeAndRepaint() {
revalidate();
repaint();
}
Sizes the header and marks it as needing display. Equivalent
to revalidate followed by repaint. |
public void setColumnModel(TableColumnModel columnModel) {
if (columnModel == null) {
throw new IllegalArgumentException("Cannot set a null ColumnModel");
}
TableColumnModel old = this.columnModel;
if (columnModel != old) {
if (old != null) {
old.removeColumnModelListener(this);
}
this.columnModel = columnModel;
columnModel.addColumnModelListener(this);
firePropertyChange("columnModel", old, columnModel);
resizeAndRepaint();
}
}
Sets the column model for this table to newModel and registers
for listener notifications from the new column model. |
public void setDefaultRenderer(TableCellRenderer defaultRenderer) {
this.defaultRenderer = defaultRenderer;
}
Sets the default renderer to be used when no headerRenderer
is defined by a TableColumn. |
public void setDraggedColumn(TableColumn aColumn) {
draggedColumn = aColumn;
}
Sets the header's draggedColumn to aColumn.
Application code will not use this method explicitly, it is used
internally by the column dragging mechanism. |
public void setDraggedDistance(int distance) {
draggedDistance = distance;
}
Sets the header's draggedDistance to distance. |
public void setReorderingAllowed(boolean reorderingAllowed) {
boolean old = this.reorderingAllowed;
this.reorderingAllowed = reorderingAllowed;
firePropertyChange("reorderingAllowed", old, reorderingAllowed);
}
Sets whether the user can drag column headers to reorder columns. |
public void setResizingAllowed(boolean resizingAllowed) {
boolean old = this.resizingAllowed;
this.resizingAllowed = resizingAllowed;
firePropertyChange("resizingAllowed", old, resizingAllowed);
}
Sets whether the user can resize columns by dragging between headers. |
public void setResizingColumn(TableColumn aColumn) {
resizingColumn = aColumn;
}
Sets the header's resizingColumn to aColumn.
Application code will not use this method explicitly, it
is used internally by the column sizing mechanism. |
public void setTable(JTable table) {
JTable old = this.table;
this.table = table;
firePropertyChange("table", old, table);
}
Sets the table associated with this header. |
public void setUI(TableHeaderUI ui) {
if (this.ui != ui) {
super.setUI(ui);
repaint();
}
}
Sets the look and feel (L&F) object that renders this component. |
public void setUpdateTableInRealTime(boolean flag) {
updateTableInRealTime = flag;
}
Obsolete as of Java 2 platform v1.3. Real time repaints, in response to
column dragging or resizing, are now unconditional. |
public void updateUI() {
setUI((TableHeaderUI)UIManager.getUI(this));
TableCellRenderer renderer = getDefaultRenderer();
if (renderer instanceof Component) {
SwingUtilities.updateComponentTreeUI((Component)renderer);
}
}
Notification from the UIManager that the look and feel
(L&F) has changed.
Replaces the current UI object with the latest version from the
UIManager. |