JIDE 3.5.15

com.jidesoft.grid
Class SortTableHeaderRenderer

java.lang.Object
  extended by com.jidesoft.grid.SortTableHeaderRenderer
All Implemented Interfaces:
UIResource, TableCellRenderer

public class SortTableHeaderRenderer
extends Object
implements TableCellRenderer, UIResource

The SortTableHeaderRenderer will consider \n in headings and display them on multiple lines.
'Date of\nbirth' will be displayed on two lines. 'Date of' on the first, birth on the second.
'Date of birth' will be displayed on one lines,

In addition to multiple line feature, it will also show the sort order and sort direction if there is a sort model defined for the table and the column is in that model.


Nested Class Summary
static interface SortTableHeaderRenderer.SortArrow
          An interface for SortArrow, the arrow which is used to display on the table header to indicate sort direction and sort index.
 
Field Summary
protected  JPanel _headerPanel
           
protected  com.jidesoft.grid.SortTableHeaderRenderer.SortPanel _sortPanel
           
protected  JPanel _titlePanel
           
 
Constructor Summary
SortTableHeaderRenderer()
           
SortTableHeaderRenderer(int alignment)
           
 
Method Summary
protected  JLabel createLabel(Icon icon)
           
protected  JLabel createLabel(String text)
           
protected  SortTableHeaderRenderer.SortArrow createSortArrow()
          Creates the component to display the sort arrow.
 int getAlignment()
          Get the alignment of the header renderer.
 int getDefaultHeaderWidth(String title)
          Get an approximation of the width of the title based on the width in characters.
 Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
           
protected  void initComponents()
          Creation of the header panel.
 boolean isSortArrowVisible()
          Get the flag indicating if the sort arrow is visible in the renderer while sorting.
 void setAlignment(int alignment)
          Set the alignment of the header renderer.
 void setSortArrowVisible(boolean sortArrowVisible)
          Set the flag indicating if the sort arrow is visible in the renderer while sorting.
 void updateSortPanel(JTable table, int column)
          Update the sort parameters for this component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_headerPanel

protected JPanel _headerPanel

_titlePanel

protected JPanel _titlePanel

_sortPanel

protected com.jidesoft.grid.SortTableHeaderRenderer.SortPanel _sortPanel
Constructor Detail

SortTableHeaderRenderer

public SortTableHeaderRenderer()

SortTableHeaderRenderer

public SortTableHeaderRenderer(int alignment)
Method Detail

getTableCellRendererComponent

public Component getTableCellRendererComponent(JTable table,
                                               Object value,
                                               boolean isSelected,
                                               boolean hasFocus,
                                               int row,
                                               int column)
Specified by:
getTableCellRendererComponent in interface TableCellRenderer

getDefaultHeaderWidth

public int getDefaultHeaderWidth(String title)
Get an approximation of the width of the title based on the width in characters. This is much faster than getTitleSize() which instantiates the actual components and then gets the preferred size of those components. It doesn't matter too much that this is an approximation because table views should define a width explicitly if it's important. Also, basing the default width on the header label takes no account of whether data in the column will fit.

Parameters:
title - the title.
Returns:
the header width.

initComponents

protected void initComponents()
Creation of the header panel.


createLabel

protected JLabel createLabel(Icon icon)

createLabel

protected JLabel createLabel(String text)

updateSortPanel

public void updateSortPanel(JTable table,
                            int column)
Update the sort parameters for this component. This will result in the component changing its columns number and direction if necessary.

Parameters:
table - the table
column - The column as display (0 leftmost)

isSortArrowVisible

public boolean isSortArrowVisible()
Get the flag indicating if the sort arrow is visible in the renderer while sorting.

By default, the flag is true. You could set it to false if you don't want to show the sort arrow up.

Returns:
true if the sort arrow is visible. Otherwise false.

setSortArrowVisible

public void setSortArrowVisible(boolean sortArrowVisible)
Set the flag indicating if the sort arrow is visible in the renderer while sorting.

Parameters:
sortArrowVisible - the flag
See Also:
isSortArrowVisible()

getAlignment

public int getAlignment()
Get the alignment of the header renderer.

By default the value is javax.swing.SwingConstants.CENTER. You could set it to other alignments if you want.

Returns:
the alignment.

setAlignment

public void setAlignment(int alignment)
Set the alignment of the header renderer.

Parameters:
alignment - the alignment
See Also:
getAlignment()

createSortArrow

protected SortTableHeaderRenderer.SortArrow createSortArrow()
Creates the component to display the sort arrow. Subclass can implement SortArrow and create their own component. However it must be a JComponent.

Returns:
SortArrow

JIDE 3.5.15