本文整理汇总了Java中javax.swing.RowSorter类的典型用法代码示例。如果您正苦于以下问题:Java RowSorter类的具体用法?Java RowSorter怎么用?Java RowSorter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RowSorter类属于javax.swing包,在下文中一共展示了RowSorter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setSortKeys
import javax.swing.RowSorter; //导入依赖的package包/类
public void setSortKeys(List newKeys) {
if (newKeys == null) {
setSortKeysImpl(newKeys);
return;
}
RowSorter.SortKey oldKey = getSortKey();
RowSorter.SortKey newKey = (RowSorter.SortKey)newKeys.get(0);
if (oldKey == null || oldKey.getColumn() != newKey.getColumn()) {
// Use defined initial SortOrder for a newly sorted column
setSortColumn(newKey.getColumn());
} else {
setSortKeysImpl(newKeys);
}
}
示例2: getIcon
import javax.swing.RowSorter; //导入依赖的package包/类
/**
* Overridden to return an icon suitable to a sorted column, or null if the
* column is unsorted. The icon for the primary sorted column is fully
* opaque, and the opacity is reduced by a factor of
* <code>alpha</code> for each subsequent sort index.
*
* @param table the <code>JTable</code>.
* @param column the column index.
* @return the sort icon with appropriate opacity, or null if the column is
* unsorted.
*/
@Override
public Icon getIcon(JTable table, int column) {
float computedAlpha = 1.0F;
for (RowSorter.SortKey sortKey : table.getRowSorter().getSortKeys()) {
if (table.convertColumnIndexToView(sortKey.getColumn()) == column) {
switch (sortKey.getSortOrder()) {
case ASCENDING:
return new AlphaIcon(UIManager.getIcon("Table.ascendingSortIcon"), computedAlpha);
case DESCENDING:
return new AlphaIcon(UIManager.getIcon("Table.descendingSortIcon"), computedAlpha);
default:
// Just to remove unmatched case warning
}
}
computedAlpha *= alpha;
}
return null;
}
示例3: getColumnSortOrder
import javax.swing.RowSorter; //导入依赖的package包/类
public static SortOrder getColumnSortOrder(JTable table, int column)
{
SortOrder rv = null;
if (table == null || table.getRowSorter() == null)
{
return rv;
}
java.util.List<? extends RowSorter.SortKey> sortKeys = table
.getRowSorter().getSortKeys();
if (sortKeys.size() > 0 && sortKeys.get(0).getColumn() == table
.convertColumnIndexToModel(column))
{
rv = sortKeys.get(0).getSortOrder();
}
return rv;
}
示例4: DetailsView
import javax.swing.RowSorter; //导入依赖的package包/类
/** Creates new form DetailsView
* @param rowSorter
*/
public DetailsView(List<Row> rows, int size, DataModel dataModel, Table table, int rowIndex, RowSorter<? extends TableModel> rowSorter, boolean showSpinner) {
this.table = table;
this.rows = rows;
this.rowSorter = rowSorter;
initComponents();
if (rowSorter != null) {
rowIndex = rowSorter.convertRowIndexToView(rowIndex);
}
final SpinnerNumberModel model = new SpinnerNumberModel(rowIndex + 1, 1, size, -1);
rowSpinner.setModel(model);
rowSpinner.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
setCurrentRow((Integer) model.getValue() - 1, true);
}
});
if (!showSpinner) {
jLabel1.setVisible(false);
rowSpinner.setVisible(false);
// jScrollPane1.setBorder(null);
jScrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
jScrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
}
setCurrentRow(rowIndex, showSpinner);
}
示例5: setSourceModel
import javax.swing.RowSorter; //导入依赖的package包/类
public void setSourceModel(ListSelectionModel listSelectionModel,
RowSorter<?> rowSorter) {
if (this.sourceModel != null) {
this.sourceModel.removeListSelectionListener(targetModelSync);
}
if (rowSorter == null) {
targetModelSync.setIndexConverter(null);
sourceModelSync.setIndexConverter(null);
} else {
targetModelSync
.setIndexConverter(new ViewToModelRowSorterConverter(
rowSorter));
sourceModelSync
.setIndexConverter(new ModelToViewRowSorterConverter(
rowSorter));
}
this.sourceModel = listSelectionModel;
if (this.sourceModel != null) {
sourceModelSync.setTargetModel(sourceModel, targetModelSync);
this.sourceModel.addListSelectionListener(targetModelSync);
}
}
示例6: updateClusterTable
import javax.swing.RowSorter; //导入依赖的package包/类
private void updateClusterTable() {
int index = annotationSetCombo.getSelectedIndex();
AnnotationSet annotationSet = annotationSetCombo.getItemAt(index).getValue();
ClusterTableModel clusterModel = new ClusterTableModel(annotationSet);
int widths[] = getColumnWidths(clusterTable);
clusterTable.setModel(clusterModel);
setColumnWidths(clusterTable, widths);
TableColumn collapsedColumn = clusterTable.getColumnModel().getColumn(ClusterTableModel.COLLAPSED_COLUMN_INDEX);
collapsedColumn.setCellRenderer(new ClusterTableCollapsedCellRenderer(iconManager));
// sort
TableRowSorter<TableModel> sorter = new TableRowSorter<>(clusterTable.getModel());
clusterTable.setRowSorter(sorter);
List<SortKey> sortKeys = new ArrayList<>(2);
sortKeys.add(new RowSorter.SortKey(ClusterTableModel.NODES_COLUMN_INDEX, SortOrder.DESCENDING));
sortKeys.add(new RowSorter.SortKey(ClusterTableModel.CLUSTER_COLUMN_INDEX, SortOrder.ASCENDING));
sorter.setSortKeys(sortKeys);
sorter.sort();
}
示例7: getIcon
import javax.swing.RowSorter; //导入依赖的package包/类
/**
* Overridden to return an icon suitable to a sorted column, or null if the column is unsorted.
* The icon for the primary sorted column is fully opaque, and the opacity is reduced by a
* factor of <code>alpha</code> for each subsequent sort index.
*
* @param table the <code>JTable</code>.
* @param column the column index.
* @return the sort icon with appropriate opacity, or null if the column is unsorted.
*/
public Icon getIcon(JTable table, int column) {
float computedAlpha = 1.0F;
for (RowSorter.SortKey sortKey : table.getRowSorter().getSortKeys()) {
if (table.convertColumnIndexToView(sortKey.getColumn()) == column) {
switch (sortKey.getSortOrder()) {
case ASCENDING:
return new AlphaIcon(UIManager.getIcon("Table.ascendingSortIcon"), computedAlpha);
case DESCENDING:
return new AlphaIcon(UIManager.getIcon("Table.descendingSortIcon"), computedAlpha);
}
}
computedAlpha *= alpha;
}
return null;
}
示例8: setTeamProjectTable
import javax.swing.RowSorter; //导入依赖的package包/类
public void setTeamProjectTable(final ServerContextTableModel tableModel, final ListSelectionModel selectionModel) {
teamProjectTable.setModel(tableModel);
teamProjectTable.setSelectionModel(selectionModel);
// Setup table sorter
final RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel);
teamProjectTable.setRowSorter(sorter);
// Attach an index converter to fix the indexes if the user sorts the list
tableModel.setSelectionConverter(new TableModelSelectionConverter() {
@Override
public int convertRowIndexToModel(int viewRowIndex) {
if (viewRowIndex >= 0) {
return teamProjectTable.convertRowIndexToModel(viewRowIndex);
}
return viewRowIndex;
}
});
}
示例9: setContextTable
import javax.swing.RowSorter; //导入依赖的package包/类
public void setContextTable(final ServerContextTableModel tableModel, final ListSelectionModel selectionModel) {
contextTable.setModel(tableModel);
contextTable.setSelectionModel(selectionModel);
// Setup table sorter
final RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel);
contextTable.setRowSorter(sorter);
// Attach an index converter to fix the indexes if the user sorts the list
tableModel.setSelectionConverter(new TableModelSelectionConverter() {
@Override
public int convertRowIndexToModel(int viewRowIndex) {
if (viewRowIndex >= 0) {
return contextTable.convertRowIndexToModel(viewRowIndex);
}
return viewRowIndex;
}
});
}
示例10: setWorkItemTable
import javax.swing.RowSorter; //导入依赖的package包/类
public void setWorkItemTable(final WorkItemsTableModel tableModel, final ListSelectionModel selectionModel) {
workItemTable.setModel(tableModel);
workItemTable.setSelectionModel(selectionModel);
// Setup table sorter
RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel);
workItemTable.setRowSorter(sorter);
// Attach an index converter to fix the indexes if the user sorts the list
tableModel.setSelectionConverter(new TableModelSelectionConverter() {
@Override
public int convertRowIndexToModel(int viewRowIndex) {
if (viewRowIndex >= 0) {
return workItemTable.convertRowIndexToModel(viewRowIndex);
}
return viewRowIndex;
}
});
}
示例11: setRepositoryTable
import javax.swing.RowSorter; //导入依赖的package包/类
public void setRepositoryTable(final ServerContextTableModel tableModel, final ListSelectionModel selectionModel) {
repositoryTable.setModel(tableModel);
repositoryTable.setSelectionModel(selectionModel);
// Setup table sorter
RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel);
repositoryTable.setRowSorter(sorter);
// Attach an index converter to fix the indexes if the user sorts the list
tableModel.setSelectionConverter(new TableModelSelectionConverter() {
@Override
public int convertRowIndexToModel(int viewRowIndex) {
if (viewRowIndex >= 0) {
return repositoryTable.convertRowIndexToModel(viewRowIndex);
}
return viewRowIndex;
}
});
}
示例12: getSortedColumn
import javax.swing.RowSorter; //导入依赖的package包/类
/**
* Returns the primary sort column, or null if nothing sorted or no sortKey
* corresponds to a TableColumn currently contained in the TableColumnModel.
*
* @return the currently interactively sorted TableColumn or null if there
* is not sorter active or if the sorted column index does not
* correspond to any column in the TableColumnModel.
*/
public TableColumn getSortedColumn() {
// bloody hack: get primary SortKey and
// check if there's a column with it available
RowSorter<?> controller = getRowSorter();
if (controller != null) {
// PENDING JW: must use RowSorter?
SortKey sortKey = SortUtils.getFirstSortingKey(controller
.getSortKeys());
if (sortKey != null) {
int sorterColumn = sortKey.getColumn();
List<TableColumn> columns = getColumns(true);
for (Iterator<TableColumn> iter = columns.iterator(); iter
.hasNext();) {
TableColumn column = iter.next();
if (column.getModelIndex() == sorterColumn) {
return column;
}
}
}
}
return null;
}
示例13: mouseClicked
import javax.swing.RowSorter; //导入依赖的package包/类
@Override
public void mouseClicked( MouseEvent e ) {
JBroTableHeader header = getHeader();
if ( !header.isEnabled() )
return;
Point point = e.getPoint();
JBroTableColumn column = getColumnAtPoint( point );
if ( column == null )
return;
if ( isLeaf( column ) && e.getClickCount() == 1 && SwingUtilities.isLeftMouseButton( e ) ) {
JTable table = header.getTable();
RowSorter sorter;
if ( table != null && ( sorter = table.getRowSorter() ) != null ) {
int columnIndex = column.getModelIndex();
if ( columnIndex != -1 ) {
sorter.toggleSortOrder( columnIndex );
header.repaint();
}
}
}
}
示例14: toNumericKeys
import javax.swing.RowSorter; //导入依赖的package包/类
private RowSorter.SortKey[] toNumericKeys( SortKey... modelColumns ) {
if ( modelColumns != null && modelColumns.length != 0 ) {
JBroTable table = getTable();
ModelData data = table.getData();
RowSorter.SortKey keys[] = new RowSorter.SortKey[ modelColumns.length ];
for ( int i = 0; i < modelColumns.length; i++ ) {
SortKey modelColumn = modelColumns[ i ];
int col = data.getIndexOfModelField( modelColumn.getColumn() );
if ( col < 0 )
throw new IllegalArgumentException( "Field \"" + modelColumn.getColumn() + "\" not found" );
RowSorter.SortKey key = new RowSorter.SortKey( col, modelColumn.getSortOrder() );
keys[ i ] = key;
}
return keys;
}
return null;
}
示例15: toStringKeys
import javax.swing.RowSorter; //导入依赖的package包/类
private SortKey[] toStringKeys( RowSorter.SortKey... modelColumns ) {
if ( modelColumns != null && modelColumns.length != 0 ) {
JBroTable table = getTable();
ModelData data = table.getData();
ModelField fields[] = data.getFields();
SortKey keys[] = new SortKey[ modelColumns.length ];
for ( int i = 0; i < modelColumns.length; i++ ) {
RowSorter.SortKey modelColumn = modelColumns[ i ];
ModelField col = fields[ modelColumn.getColumn() ];
SortKey key = new SortKey( col.getIdentifier(), modelColumn.getSortOrder() );
keys[ i ] = key;
}
return keys;
}
return EMPTY_ARRAY;
}