本文整理汇总了Java中javax.swing.table.TableRowSorter.setComparator方法的典型用法代码示例。如果您正苦于以下问题:Java TableRowSorter.setComparator方法的具体用法?Java TableRowSorter.setComparator怎么用?Java TableRowSorter.setComparator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.table.TableRowSorter
的用法示例。
在下文中一共展示了TableRowSorter.setComparator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeLocalVars
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
protected void initializeLocalVars()
{
super.initializeLocalVars();
Enumeration<TableColumn> e = getColumnModel().getColumns();
int i = 0;
while(e.hasMoreElements() && i < attributes.length) {
e.nextElement().setCellRenderer(new NameTableCellRenderer(attributes[i++]));
}
getColumnModel().getColumn(0).setMinWidth(0);
getColumnModel().getColumn(0).setPreferredWidth(3);
TableRowSorter<NameTableModel/*<T>*/> sorter =
new TableRowSorter<NameTableModel/*<T>*/>((NameTableModel/*<T>*/)getModel());
for (NameUsageAttribute attribute : attributes) {
sorter.setComparator(attribute.ordinal(), new NameUsageAttributeComparator(attribute));
}
setRowSorter(sorter);
setDragEnabled(true);
}
示例2: TableData
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
public TableData(DefaultTableModel defaultTableModel) {
super(defaultTableModel);
setAutoCreateRowSorter(true);
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
((DefaultTableModel) getModel()).setDataVector(new String[1][7],
columnName);
getTableHeader().setResizingAllowed(true);
getColumnModel().getColumn(0).setPreferredWidth(70);
getColumnModel().getColumn(1).setPreferredWidth(255);
getColumnModel().getColumn(2).setPreferredWidth(215);
getColumnModel().getColumn(3).setPreferredWidth(60);
getColumnModel().getColumn(4).setPreferredWidth(90);
getColumnModel().getColumn(5).setPreferredWidth(100);
getColumnModel().getColumn(1).setCellRenderer(
new ItalicCellRenderer());
TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(
this.getModel());
setRowSorter(sorter);
sorter.setComparator(4, new StringComparator());
sorter.setComparator(5, new StringComparator());
sorter.setComparator(6, new StringComparator());
}
示例3: TableData
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
public TableData(DefaultTableModel defaultTableModel) {
super(defaultTableModel);
setAutoCreateRowSorter(true);
getTableHeader().setReorderingAllowed(false);
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
getTableHeader().setResizingAllowed(true);
((DefaultTableModel) getModel()).setDataVector(
new String[1][9], columnName);
getColumnModel().getColumn(0).setPreferredWidth(70);
getColumnModel().getColumn(1).setPreferredWidth(255);
getColumnModel().getColumn(2).setPreferredWidth(215);
getColumnModel().getColumn(3).setPreferredWidth(60);
getColumnModel().getColumn(4).setPreferredWidth(45);
getColumnModel().getColumn(5).setPreferredWidth(45);
getColumnModel().getColumn(6).setPreferredWidth(70);
getColumnModel().getColumn(7).setPreferredWidth(70);
getColumnModel().getColumn(8).setPreferredWidth(100);
getColumnModel().getColumn(1).setCellRenderer(
new ItalicCellRenderer());
TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(
this.getModel());
sorter.setComparator(4, new StringComparator());
sorter.setComparator(5, new StringComparator());
sorter.setComparator(6, new StringComparator());
setRowSorter(sorter);
}
示例4: CResultsTable
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
/**
* Creates a new results table.
*
* @param graph Graph where the highlighting happens.
* @param model Provides the results to display.
*/
public CResultsTable(final ZyGraph graph, final CSpecialInstructionsModel model) {
m_graph = graph;
m_model = model;
m_tableModel = new CResultsTableModel(model);
setModel(m_tableModel);
final TableRowSorter<CResultsTableModel> sorter =
new TableRowSorter<CResultsTableModel>(m_tableModel);
sorter.setComparator(CResultsTableModel.TYPE_COLUMN, new CTypeComparator());
sorter.setComparator(CResultsTableModel.ADDRESS_COLUMN, new HexStringComparator());
setRowSorter(sorter);
// Make sure that the status cells are colored.
getColumnModel()
.getColumn(CResultsTableModel.TYPE_COLUMN).setCellRenderer(new CTypeColumnRenderer());
getColumnModel()
.getColumn(CResultsTableModel.INSTRUCTION_COLUMN).setCellRenderer(new CMonospaceRenderer());
final InternalSelectionListener listener = new InternalSelectionListener();
getSelectionModel().addListSelectionListener(listener);
addMouseListener(listener);
}
示例5: getJTablePjtList
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
/**
* This method initializes jTablePjtList
*
* @return javax.swing.JTable
*/
@SuppressWarnings("unchecked")
private JTable getJTablePjtList() {
if (jTablePjtList == null) {
jTablePjtList = new JTable(getProjectTableModel());
getProjectTableModel().setColumnWidth(jTablePjtList);
getProjectTableModel().setColumnType(jTablePjtList);
jTablePjtList.addMouseListener(new ProjectTableClickAction());
TableRowSorter sorter = new TableRowSorter(managedProjectTableModel);
sorter.setComparator(ManagedProjectTableModel.COL_DELETE, new ProjectTableComparator());
sorter.setComparator(ManagedProjectTableModel.COL_PROJECT_NAME, new ProjectTableComparator());
sorter.setComparator(ManagedProjectTableModel.COL_ANALYZE_TARGET, new ProjectTableComparator());
sorter.setComparator(ManagedProjectTableModel.COL_ANALYZE_STATUS, new ProjectTableComparator());
sorter.setComparator(ManagedProjectTableModel.COL_SOURCE_LOCATION, new ProjectTableComparator());
sorter.toggleSortOrder(ManagedProjectTableModel.COL_PROJECT_NAME);
jTablePjtList.setRowSorter(sorter);
}
return jTablePjtList;
}
示例6: configureSorter
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
void configureSorter(TableRowSorter<TableModel> sorter) {
sorter.setComparator(0, (DomainRow d1,
DomainRow d2) -> String.CASE_INSENSITIVE_ORDER.compare(d1.getDomain()
.getName(),
d2.getDomain()
.getName()));
}
示例7: createRowSorter
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
private TableRowSorter<ReturnsSummaryTableModel> createRowSorter(ReturnsSummaryTableModel model, List<String> columns) {
TableRowSorter<ReturnsSummaryTableModel> rowSorter = new TableRowSorter<ReturnsSummaryTableModel>(model);
for (int i = 0; i < columns.size(); i++) {
rowSorter.setComparator(i, DoubleAsStringComparator.instance);
}
return rowSorter;
}
示例8: createRowSorter
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
private TableRowSorter<StockTableModel> createRowSorter(StockTableModel model, List<String> columns) {
TableRowSorter<StockTableModel> rowSorter = new TableRowSorter<StockTableModel>(model);
for (int i = 0; i < columns.size(); i++) {
rowSorter.setComparator(i, DoubleAsStringComparator.instance);
}
rowSorter.toggleSortOrder(0);
return rowSorter;
}
示例9: setRowSorter
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
public void setRowSorter(final int column, final Comparator<?> comparator) {
final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(table.getModel());
sorter.setSortsOnUpdates(true);
sorter.setComparator(column, null);
setRowSorter(sorter);
sorter.setSortKeys(Arrays.asList(new RowSorter.SortKey(column, SortOrder.ASCENDING)));
}
示例10: setLayout4JTableComponents
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
/**
* Sets the layout for the JTable of the NetworkComponents.
*/
private void setLayout4JTableComponents() {
// --- Set Sorter for the table -------------------
TableRowSorter<DefaultTableModel> tblSorter = new TableRowSorter<DefaultTableModel>(this.getDefaultTableModel4Components());
this.getJTableComponents().setRowSorter(tblSorter);
// --- Define a comparator for the first row ------
tblSorter.setComparator(0, new Comparator<String>() {
@Override
public int compare(String netCompId1, String netCompId2) {
Integer ncID1 = null;
Integer ncID2 = null;
try {
ncID1 = Integer.parseInt(netCompId1.replaceAll("\\D+",""));
ncID2 = Integer.parseInt(netCompId2.replaceAll("\\D+",""));
} catch (NumberFormatException nfe) {
}
if (ncID1!=null & ncID2!=null) {
return ncID1.compareTo(ncID2);
}
return netCompId1.compareTo(netCompId2);
}
});
// --- Define the first sort order ----------------
List<SortKey> sortKeys = new ArrayList<SortKey>();
for (int i = 0; i < this.getJTableComponents().getColumnCount(); i++) {
sortKeys.add(new SortKey(i, SortOrder.ASCENDING));
}
tblSorter.setSortKeys(sortKeys);
tblSorter.sort();
// --- Define the column widths -------------------
TableColumnModel colModel = this.getJTableComponents().getColumnModel();
colModel.getColumn(0).setPreferredWidth(40);
colModel.getColumn(0).setCellRenderer(new BasicGraphGuiTableCellRenderEditor());
colModel.getColumn(0).setCellEditor(new BasicGraphGuiTableCellRenderEditor());
colModel.getColumn(1).setPreferredWidth(40);
colModel.getColumn(1).setCellRenderer(new BasicGraphGuiTableCellRenderEditor());
colModel.getColumn(2).setPreferredWidth(30);
colModel.getColumn(2).setCellRenderer(new TableCellRenderer4Button());
colModel.getColumn(2).setCellEditor(new TableCellEditor4TableButton(getGraphController(), jTableComponents));
}
示例11: setClusterSets
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
public void setClusterSets(int[] csIDs) {
if (cl != null) {
if (!cl.isDone()) {
cl.cancel(true);
}
}
if (csIDs == null) {
table.setModel(new DefaultTableModel());
return;
}
if (csIDs.length == 0) {
table.setModel(new DefaultTableModel());
return;
}
ClusterSet cs = ClusterSetCache.getInstance(ds[0], csIDs[0]);
tm = new ObjectTableModel<>(new ClusterSet[]{cs});
table.setModel(tm);
DefaultTableColumnModel cm = new DefaultTableColumnModel();
for (int k = 0; k < tm.getColumnCount(); k++) {
TableColumn col = new TableColumn(k, 70);
col.setHeaderValue(tm.getColumnName(k));
cm.addColumn(col);
}
table.setColumnModel(cm);
cm.getColumn(0).setPreferredWidth(50);
cm.getColumn(1).setPreferredWidth(300);
TableRowSorter<ObjectTableModel<ClusterSet>> trs = new TableRowSorter<ObjectTableModel<ClusterSet>>(tm) {
@Override
public void rowsInserted(int firstRow, int endRow) {
allRowsChanged();
}
};
table.setRowSorter(trs);
TableCellEditorEx editor = new TableCellEditorEx();
for (int p = 0; p < table.getColumnCount(); p++) {
table.getColumnModel().getColumn(p).setCellEditor(editor);
trs.setComparator(p, new CustomTableRowComparator());
table.getColumnModel().getColumn(p).setHeaderRenderer(new GlassTableHeader(table.getTableHeader()));
}
table.getSelectionModel().addListSelectionListener(lsl);
table.setColumnSelectionAllowed(false);
table.setShowVerticalLines(false);
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
// frmMain.getInstance().getProfilePopup().show(table, e.getX(), e.getY());
}
}
});
table.setTransferHandler(new TableTransferHandler());
if (csIDs.length > 1) {
cl = new ClusterSetsLazyLoader(Arrays.copyOfRange(csIDs, 1, csIDs.length));
cl.execute();
}
}
示例12: configureSorter
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
void configureSorter(TableRowSorter<TableModel> sorter) {
sorter.setComparator(0, String.CASE_INSENSITIVE_ORDER);
}
示例13: CNodeChooserTable
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
/**
* Creates a new node chooser table.
*
* @param graph Provides the nodes for the table.
* @param searchField Search field whose results are displayed in the table.
*/
public CNodeChooserTable(final ZyGraph graph, final CGraphSearchField searchField) {
m_graph = Preconditions.checkNotNull(graph, "IE01773: Graph argument can't be null.");
m_searchField =
Preconditions.checkNotNull(searchField, "IE01774: Search field argument can not be null");
m_model = new CNodeChooserModel(graph);
setModel(m_model);
final TableRowSorter<CNodeChooserModel> tableSorter =
new TableRowSorter<CNodeChooserModel>(m_model);
setRowSorter(tableSorter);
tableSorter.setComparator(CNodeChooserModel.COLUMN_IN, new IntComparator());
tableSorter.setComparator(CNodeChooserModel.COLUMN_OUT, new IntComparator());
tableSorter.setComparator(CNodeChooserModel.COLUMN_ADDRESS, new LexicalComparator());
tableSorter.setComparator(CNodeChooserModel.COLUMN_COLOR, new IntComparator());
final CNodeChooserRenderer renderer =
new CNodeChooserRenderer(this, m_graph, m_searchField.getGraphSearcher());
setRowSelectionAllowed(true);
setColumnSelectionAllowed(false);
setCellSelectionEnabled(false);
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
getTableHeader().setReorderingAllowed(false);
getColumnModel().getColumn(0).setCellRenderer(renderer);
getColumnModel().getColumn(1).setCellRenderer(renderer);
getColumnModel().getColumn(2).setCellRenderer(renderer);
getColumnModel().getColumn(3).setCellRenderer(renderer);
getColumnModel().getColumn(0).setPreferredWidth(35);
getColumnModel().getColumn(1).setPreferredWidth(35);
getColumnModel().getColumn(3).setPreferredWidth(50);
getColumnModel().getColumn(0).setMaxWidth(50);
getColumnModel().getColumn(1).setMaxWidth(50);
getColumnModel().getColumn(3).setMaxWidth(50);
m_searchField.addListener(m_searchFieldListener);
m_mouselistener = new CNodeChooserMouseListener(this, graph);
addMouseListener(m_mouselistener);
m_graph.addListener((INaviGraphListener) m_viewListener);
m_graph.addListener((IZyGraphSelectionListener) m_viewListener);
initializeViewListeners(m_graph.getRawView());
}
示例14: SRLRace
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
public SRLRace(Window parent, ContextMenuListener streamsContextMenuListener) {
super(parent);
this.streamsContextMenuListener = streamsContextMenuListener;
this.raceContextMenuListener = new RaceContextMenuListener();
Timer timer = new Timer(UPDATE_DELAY, new UpdateTimer());
timer.setRepeats(true);
timer.start();
setLayout(new GridBagLayout());
GridBagConstraints gbc;
gbc = GuiUtil.makeGbc(1, 0, 1, 1, GridBagConstraints.EAST);
id = new LinkLabel("", new MyLinkLabelListener());
id.addMouseListener(new ContextMenuOpener());
gbc.weightx = 0.5;
gbc.insets = new Insets(5, 5, 0, 5);
add(id, gbc);
gbc = GuiUtil.makeGbc(0, 4, 2, 1, GridBagConstraints.WEST);
add(state, gbc);
gbc = GuiUtil.makeGbc(1, 4, 1, 1, GridBagConstraints.EAST);
add(time, gbc);
gbc = GuiUtil.makeGbc(0, 0, 1, 1, GridBagConstraints.WEST);
gbc.insets = new Insets(5, 5, 0, 5);
add(new JLabel("Game:"), gbc);
gbc = GuiUtil.makeGbc(0, 1, 2, 1, GridBagConstraints.WEST);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 1;
game.setEditable(false);
add(game, gbc);
gbc = GuiUtil.makeGbc(0, 2, 1, 1, GridBagConstraints.WEST);
gbc.insets = new Insets(5, 5, 0, 5);
add(new JLabel("Goal:"), gbc);
gbc = GuiUtil.makeGbc(0, 3, 2, 1, GridBagConstraints.WEST);
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1;
goal.setEditable(false);
goal.setBackground(game.getBackground());
goal.setBorder(game.getBorder());
goal.setLinkListener(new MyLinkListener());
goal.setMargin(game.getMargin());
add(goal, gbc);
entrantsTable.setModel(entrants);
entrantsTable.setFillsViewportHeight(true);
entrantsTable.addMouseListener(new MouseClicks());
TableRowSorter<MyTableModel> sorter = new TableRowSorter<>(entrants);
entrantsTable.setRowSorter(sorter);
TableColumnModel columns = entrantsTable.getColumnModel();
columns.getColumn(0).setMaxWidth(40);
columns.getColumn(2).setMaxWidth(80);
columns.getColumn(3).setMinWidth(70);
columns.getColumn(3).setMaxWidth(120);
columns.getColumn(4).setMinWidth(40);
columns.getColumn(4).setMaxWidth(40);
sorter.setComparator(0, new PlaceSorter());
columns.getColumn(0).setCellRenderer(new PlaceRenderer());
columns.getColumn(3).setCellRenderer(new StateRenderer());
//sorter.toggleSortOrder(0);
gbc = GuiUtil.makeGbc(0, 5, 2, 1, GridBagConstraints.WEST);
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1;
gbc.weighty = 1;
add(new JScrollPane(entrantsTable), gbc);
setPreferredSize(new Dimension(350, 410));
setSize(new Dimension(340, 410));
setMinimumSize(new Dimension(200,300));
}
示例15: addComponents
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
/**
* Add components to the pane.
*/
private void addComponents() {
JPanel topPanel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
TableModel model = new NonEditableTableModel(columns, 0);
cacheTable = new JTable(model);
cacheTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
cacheTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
final public void valueChanged(ListSelectionEvent listSelectionEvent) {
// If no row has been selected, disable the delete button, else enable it
if (cacheTable.getSelectionModel().isSelectionEmpty()) {
deleteButton.setEnabled(false);
}
else {
deleteButton.setEnabled(true);
}
}
});
cacheTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
cacheTable.setPreferredScrollableViewportSize(new Dimension(600, 200));
cacheTable.setFillsViewportHeight(true);
JScrollPane scrollPane = new JScrollPane(cacheTable);
TableRowSorter<TableModel> tableSorter = new TableRowSorter<>(model);
final Comparator<Comparable<?>> comparator = new Comparator<Comparable<?>>() { // General purpose Comparator
@Override
@SuppressWarnings("unchecked")
public final int compare(final Comparable a, final Comparable b) {
return a.compareTo(b);
}
};
tableSorter.setComparator(1, comparator); // Comparator for path column.
tableSorter.setComparator(4, comparator); // Comparator for size column.
tableSorter.setComparator(5, comparator); // Comparator for modified column.
cacheTable.setRowSorter(tableSorter);
final DefaultTableCellRenderer tableCellRenderer = new DefaultTableCellRenderer() {
@Override
public final Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
switch (column) {
case 1: // Path column
// Render absolute path
super.setText(((File)value).getAbsolutePath());
break;
case 4: // Size column
// Render size formatted to default locale's number format
super.setText(NumberFormat.getInstance().format(value));
break;
case 5: // last modified column
// Render modify date formatted to default locale's date format
super.setText(DateFormat.getDateInstance().format(value));
}
return this;
}
};
// TableCellRenderer for path column
cacheTable.getColumn(this.columns[1]).setCellRenderer(tableCellRenderer);
// TableCellRenderer for size column
cacheTable.getColumn(this.columns[4]).setCellRenderer(tableCellRenderer);
// TableCellRenderer for last modified column
cacheTable.getColumn(this.columns[5]).setCellRenderer(tableCellRenderer);
c.weightx = 1;
c.weighty = 1;
c.gridx = 0;
c.gridy = 0;
topPanel.add(scrollPane, c);
this.add(topPanel, BorderLayout.CENTER);
this.add(createButtonPanel(), BorderLayout.SOUTH);
}