table.setSortOrder("PERSON_ID", SortOrder.DESCENDING); table.toggleSortOder(4); table.resetSortOrder();
Sorting sequence can be configured per column by setting the TableColumnExt's comparator
property. Sorting can be disabled per column - setting the TableColumnExt's sortable
or per table by {@link #setSortable(boolean)}. The table takes responsibility to propagate these properties to the current sorter, if available Note that the enhanced sorting controls are effective only if the RowSorter is of type SortController, which it is by default. Different from core JTable, the autoCreateRowSorter property is enabled by default. If on, the JXTable creates and uses a default row sorter as returned by the createDefaultRowSorter method.
Typically, a JXTable is sortable by left clicking on column headers. By default, each subsequent click on a header reverses the order of the sort, and a sort arrow icon is automatically drawn on the header.
An example multiple highlighting (default striping as appropriate for the current LookAndFeel, cell foreground on matching pattern, and shading a column):
Highlighter simpleStriping = HighlighterFactory.createSimpleStriping(); PatternPredicate patternPredicate = new PatternPredicate("ˆM", 1); ColorHighlighter magenta = new ColorHighlighter(patternPredicate, null, Color.MAGENTA, null, Color.MAGENTA); Highlighter shading = new ShadingColorHighlighter( new HighlightPredicate.ColumnHighlightPredicate(1)); table.setHighlighters(simpleStriping, magenta, shading);
To fully support, JXTable registers SwingX default table renderers instead of core defaults (see {@link DefaultTableRenderer}) The recommended approach for customizing rendered content it to intall a DefaultTableRenderer configured with a custom String- and/or IconValue. F.i. assuming the cell value is a File and should be rendered by showing its name followed and date of last change:
StringValue sv = new StringValue() { public String getString(Object value) { if (!(value instanceof File)) return StringValues.TO_STRING.getString(value); return StringValues.FILE_NAME.getString(value) + ", " + StringValues.DATE_TO_STRING.getString(((File) value).lastModified()); }}; table.setCellRenderer(File.class, new DefaultTableRenderer(sv));
Note: DefaultTableCellRenderer and subclasses require a hack to play nicely with Highlighters because it has an internal "color memory" in setForeground/setBackground. The hack is applied by default which might lead to unexpected side-effects in custom renderers subclassing DTCR. See {@link #resetDefaultTableCellRendererHighlighter} for details.
Note: by default JXTable disables the alternate row striping provided by Nimbus, instead it does use the color provided by Nimbus to configure the UIColorHighlighter. Like in any other LAF without striping support, client code has to explicitly turn on striping by setting a Highlighter like:
table.addHighlighter(HighlighterFactory.createSimpleStriping());
Alternatively, if client code wants to rely on the LAF provided striping support, it can set a property in the UIManager ("early" in the application lifetime to prevent JXTable to disable Nimbus handling it. In this case it is recommended to not any of the ui-dependent Highlighters provided by the HighlighterFactory. UIManager.put("Nimbus.keepAlternateRowColor", Boolean.TRUE);
JXTable table = new JXTable(); table.addHighlighter(new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW, null, Color.RED);
JXTable provides api to vend a renderer-controlled String representation of cell content. This allows the Searchable and Highlighters to use WYSIWYM (What-You-See-Is-What-You-Match), that is pattern matching against the actual string as seen by the user.
Columns can be hidden or shown by setting the visible property on the TableColumnExt using {@link TableColumnExt#setVisible(boolean)}. Columns can also be shown or hidden from the column control popup.
The column control popup is triggered by an icon drawn to the far right of the column headers, above the table's scrollbar (when installed in a JScrollPane). The popup allows the user to select which columns should be shown or hidden, as well as to pack columns and turn on horizontal scrolling. To show or hide the column control, use the {@link #setColumnControlVisible(boolean show)}method.
You can resize all columns, selected columns, or a single column using the methods like {@link #packAll()}. Packing combines several other aspects of a JXTable. If horizontal scrolling is enabled using {@link #setHorizontalScrollEnabled(boolean)}, then the scrollpane will allow the table to scroll right-left, and columns will be sized to their preferred size. To control the preferred sizing of a column, you can provide a prototype value for the column in the TableColumnExt using {@link TableColumnExt#setPrototypeValue(Object)}. The prototype is used as an indicator of the preferred size of the column. This can be useful if some data in a given column is very long, but where the resize algorithm would normally not pick this up.
Keys/Actions registered with this component:
Key bindings.
Client Properties.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|