本文整理匯總了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;
}