de.muntjak.tinylookandfeel
Class TinyTableHeaderUI

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by javax.swing.plaf.TableHeaderUI
          extended by javax.swing.plaf.basic.BasicTableHeaderUI
              extended by de.muntjak.tinylookandfeel.TinyTableHeaderUI

public class TinyTableHeaderUI
extends javax.swing.plaf.basic.BasicTableHeaderUI

Aside from being the ui delegate for TinyLaF table headers, this class manages user gestures on sortable table headers.

At sortColumns(int[], int[], JTable) you can initiate sorting. At setHorizontalAlignments(int[]) you can specify the horizontal alignments of table header renderers.

Each table header has its own instance of TinyTableHeaderUI. You can obtain it with code like this:

 JTable table = new JTable(new MySortableTableModel());
 TableHeaderUI headerUI = table.getTableHeader().getUI();
 
 if(headerUI instanceof TinyTableHeaderUI) {
     // do your thing ...
 }


Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.plaf.basic.BasicTableHeaderUI
javax.swing.plaf.basic.BasicTableHeaderUI.MouseInputHandler
 
Constructor Summary
TinyTableHeaderUI()
           
 
Method Summary
static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent header)
          Returns a new instance of TinyTableHeaderUI.
 java.awt.Dimension getPreferredSize(javax.swing.JComponent c)
          Return the preferred size of the header.
 void setHorizontalAlignments(int[] alignments)
          Sets horizontal alignments of table header renderers where an index in the argument array corresponds to a column index.
 void sortColumns(int[] columns, int[] sortingDirections, javax.swing.JTable table)
          Call this method to programmatically initiate sorting on (sortable) table models.
 
Methods inherited from class javax.swing.plaf.basic.BasicTableHeaderUI
getMaximumSize, getMinimumSize, installUI, paint, uninstallUI
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, update
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TinyTableHeaderUI

public TinyTableHeaderUI()
Method Detail

createUI

public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent header)
Returns a new instance of TinyTableHeaderUI.


getPreferredSize

public java.awt.Dimension getPreferredSize(javax.swing.JComponent c)
Return the preferred size of the header. The preferred height is the maximum of the preferred heights of all of the components provided by the header renderers. The preferred width is the sum of the preferred widths of each column (plus inter-cell spacing).

Overrides:
getPreferredSize in class javax.swing.plaf.basic.BasicTableHeaderUI

setHorizontalAlignments

public void setHorizontalAlignments(int[] alignments)
Sets horizontal alignments of table header renderers where an index in the argument array corresponds to a column index.
Note: If the length of the argument array is less than the number of columns, unspecified columns default to CENTER alignment. If the length of the argument array is greater than the number of columns, surplus information will be ignored.

Parameters:
alignments - array of the following constants defined in SwingConstants: LEFT, CENTER, RIGHT, LEADING or TRAILING.

sortColumns

public void sortColumns(int[] columns,
                        int[] sortingDirections,
                        javax.swing.JTable table)
Call this method to programmatically initiate sorting on (sortable) table models. Especially if your data is sorted by default, you should call this method before the table is displayed the first time.

Parameters:
columns - array of column indices sorted by priority (highest priority first)
sortingDirections - array containing the sorting direction for each sorted column. Values are either
  • de.muntjak.tinylookandfeel.table.SortableTableData.SORT_ASCENDING or
  • de.muntjak.tinylookandfeel.table.SortableTableData.SORT_DESCENDING
table - the table displaying the data
Throws:
java.lang.IllegalArgumentException - If any of the arguments is null or arguments colums and sortingDirections are of different length.