public MyRenderComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) { super(); this.table = table; this.col = col; if (value != null) { setText(value.toString()); } else { setText(""); } setOpaque(false); setFont(UIManager.getFont("TableHeader.font")); setForeground(UIManager.getColor("TableHeader.foreground")); setHorizontalAlignment(JLabel.CENTER); setHorizontalTextPosition(SwingConstants.LEADING); setBorder(UIManager.getBorder("TableHeader.cellBorder")); if ((JTattooUtilities.getJavaVersion() >= 1.6) && (UIManager.getLookAndFeel() instanceof AbstractLookAndFeel)) { RowSorter rowSorter = table == null ? null : table.getRowSorter(); List keyList = rowSorter == null ? null : rowSorter.getSortKeys(); if ((keyList != null) && (keyList.size() > 0)) { RowSorter.SortKey sortKey = (RowSorter.SortKey) keyList.get(0); if (sortKey.getColumn() == table.convertColumnIndexToModel(col)) { AbstractIconFactory iconFactory = ((AbstractLookAndFeel) UIManager.getLookAndFeel()).getIconFactory(); if (sortKey.getSortOrder().equals(SortOrder.ASCENDING)) { setIcon(iconFactory.getUpArrowIcon()); } else if (sortKey.getSortOrder().equals(SortOrder.DESCENDING)) { setIcon(iconFactory.getDownArrowIcon()); } } } } gv = ColorHelper.getGrayValue(AbstractLookAndFeel.getTheme().getRolloverColor()); }
@Override public void setModel(final TableModel model) { super.setModel(model); if (model instanceof SortableColumnModel) { final SortableColumnModel sortableModel = (SortableColumnModel) model; if (sortableModel.isSortable()) { final TableRowSorter<TableModel> rowSorter = createRowSorter(model); rowSorter.setSortsOnUpdates(isSortOnUpdates()); setRowSorter(rowSorter); final RowSorter.SortKey sortKey = sortableModel.getDefaultSortKey(); if (sortKey != null && sortKey.getColumn() >= 0 && sortKey.getColumn() < model.getColumnCount()) { if (sortableModel.getColumnInfos()[sortKey.getColumn()].isSortable()) { rowSorter.setSortKeys(Arrays.asList(sortKey)); } } } else { final RowSorter<? extends TableModel> rowSorter = getRowSorter(); if (rowSorter instanceof DefaultColumnInfoBasedRowSorter) { setRowSorter(null); } } } }