javax.swing.table.TableRowSorter Java Examples

The following examples show how to use javax.swing.table.TableRowSorter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainPanel.java    From java-swing-tips with MIT License 7 votes vote down vote up
private MainPanel() {
  super(new BorderLayout());
  table.setRowSorter(new TableRowSorter<>(model));

  JScrollPane scrollPane = new JScrollPane(table);
  scrollPane.getViewport().setBackground(Color.WHITE);
  table.setComponentPopupMenu(new TablePopupMenu());
  table.setFillsViewportHeight(true);
  table.setIntercellSpacing(new Dimension());
  table.setShowGrid(false);
  table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

  TableColumn column = table.getColumnModel().getColumn(0);
  column.setMaxWidth(60);
  column.setMinWidth(60);
  column.setResizable(false);

  JButton button = new JButton("add");
  button.addActionListener(e -> addActionPerformed());
  add(button, BorderLayout.SOUTH);
  add(scrollPane);
  setPreferredSize(new Dimension(320, 240));
}
 
Example #2
Source File: FilteredTableNextRowProviderTest.java    From otroslogviewer with Apache License 2.0 6 votes vote down vote up
@Test
public void testFilteredTable() {
  JTable jTable = new JTable(10, 1);
  TableRowSorter rowSorter = new TableRowSorter(jTable.getModel());
  jTable.setRowSorter(rowSorter);
  RowFilter<TableModel, Integer> rowFilter = new RowFilter<TableModel, Integer>() {

    public boolean include(Entry<? extends TableModel, ? extends Integer> entry) {
      return entry.getIdentifier().intValue() % 2 == 0;
    }
  };

  rowSorter.setRowFilter(rowFilter);
  NextRowProvider nextRowProvider = NextRowProviderFactory.getNextFilteredTableRow(jTable);
  for (int i = 0; i < 5; i++) {
    int nextRow = nextRowProvider.getNextRow();
    assertEquals(i * 2, nextRow);
  }
  assertEquals(-1, nextRowProvider.getNextRow());
}
 
Example #3
Source File: PeakListTableWindow.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void updateFilter() {

  List<RowFilter<Object, Object>> rowSorters = new ArrayList<RowFilter<Object, Object>>();

  TableRowSorter<PeakListTableModel> sorter =
      (TableRowSorter<PeakListTableModel>) table.getRowSorter();

  String textId = "(?i)" + filterTextId.getText();
  String textIdentity = "(?i)" + filterTextIdentity.getText();
  String textComment = "(?i)" + filterTextComment.getText();

  rowSorters.add(RowFilter.regexFilter(textId, 0));
  rowSorters.add(mzFilter);
  rowSorters.add(rtFilter);
  rowSorters.add(RowFilter.regexFilter(textIdentity, 3));
  rowSorters.add(RowFilter.regexFilter(textComment, 4));

  sorter.setRowFilter(RowFilter.andFilter(rowSorters));
  table.setRowSorter(sorter);

}
 
Example #4
Source File: GUIOptionCharSetDialog.java    From PacketProxy with Apache License 2.0 6 votes vote down vote up
private JScrollPane tableScrollPane(){
	table_model = new CharSetsTableModel(getTableDataWithAvailableCharsets(), columns);
	JTable table = new JTable(table_model);
	TableColumn col = table.getColumnModel().getColumn(0);
	col.setMinWidth(50);
	col.setMaxWidth(50);
	table.addMouseListener(new MouseAdapter() {
		@Override
		public void mousePressed(MouseEvent e) {
			super.mousePressed(e);
			if(0==table.getSelectedColumn()){
				return;
			}
			table.setValueAt(!(Boolean)table.getValueAt(table.getSelectedRow(), 0), table.getSelectedRow(),0);
		}
	});
	sorter = new TableRowSorter<CharSetsTableModel>(table_model);
	table.setRowSorter(sorter);
	JScrollPane jscrollPane = new JScrollPane(table);

	return jscrollPane;
}
 
Example #5
Source File: ProfilerTreeTable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected TableRowSorter createRowSorter() {
        ProfilerRowSorter s = new ProfilerTreeTableSorter(getModel()) {
            public void allRowsChanged() {
                // Must invoke later, JTree.getRowCount() not ready yet
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() { updateColumnsPreferredWidth(); }
                });
            }
            protected void setSortKeysImpl(List newKeys) {
                // TODO: Improve to not call createComparator(newKeys) here and from super
                willBeSorted(Collections.unmodifiableList(newKeys));
                super.setSortKeysImpl(newKeys);
            }
        };
        s.setDefaultSortOrder(SortOrder.DESCENDING);
        s.setDefaultSortOrder(0, SortOrder.ASCENDING);
//        s.setSortColumn(0);
        return s;
    }
 
Example #6
Source File: ConfigTable.java    From knife with MIT License 6 votes vote down vote up
private void addClickSort() {
	TableRowSorter<ConfigTableModel> sorter = new TableRowSorter<ConfigTableModel>(ConfigTableModel);
	ConfigTable.this.setRowSorter(sorter);

	JTableHeader header = this.getTableHeader();
	header.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent e) {
			try {
				//ConfigTable.this.getRowSorter().getSortKeys().get(0).getColumn();
				sorter.getSortKeys().get(0).getColumn();
				////当Jtable中无数据时,jtable.getRowSorter()是null
			} catch (Exception e1) {
				e1.printStackTrace(new PrintWriter(BurpExtender.callbacks.getStderr(), true));//working?
			}
		}
	});
}
 
Example #7
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private MainPanel() {
  super(new BorderLayout());
  String[] empty = {"", "", ""};
  String[] columnNames = {"A", "B", "C"};
  Object[][] data = {
    {"aaa", "fff", "ggg"}, {"jjj", "ppp", "ooo"},
    {"bbb", "eee", "hhh"}, {"kkk", "qqq", "nnn"},
    {"ccc", "ddd", "iii"}, {"lll", "rrr", "mmm"},
    empty, empty, empty, empty, empty, empty
  };
  TableModel model = new DefaultTableModel(data, columnNames) {
    @Override public Class<?> getColumnClass(int column) {
      return String.class;
    }
  };
  JTable table = new JTable(model);
  table.setAutoCreateRowSorter(true);
  TableRowSorter<? extends TableModel> sorter = (TableRowSorter<? extends TableModel>) table.getRowSorter();
  IntStream.range(0, 3).forEach(i -> sorter.setComparator(i, new RowComparator(table, i)));

  add(new JScrollPane(table));
  setPreferredSize(new Dimension(320, 240));
}
 
Example #8
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private void deleteActionPerformed() {
  int[] selection = table.getSelectedRows();
  if (selection.length == 0) {
    return;
  }
  for (int i: selection) {
    int mi = table.convertRowIndexToModel(i);
    deletedRowSet.add(mi);
    SwingWorker<?, ?> worker = getSwingWorker(mi);
    if (Objects.nonNull(worker) && !worker.isDone()) {
      worker.cancel(true);
      // executor.remove(worker);
    }
    // worker = null;
  }
  RowSorter<? extends TableModel> sorter = table.getRowSorter();
  ((TableRowSorter<? extends TableModel>) sorter).setRowFilter(new RowFilter<TableModel, Integer>() {
    @Override public boolean include(Entry<? extends TableModel, ? extends Integer> entry) {
      return !deletedRowSet.contains(entry.getIdentifier());
    }
  });
  table.clearSelection();
  table.repaint();
}
 
Example #9
Source File: DefaultsDisplay.java    From littleluck with Apache License 2.0 6 votes vote down vote up
protected JComponent createFilterControl() {
          
    onlyVisualsCheckBox = new JCheckBox("Show Only Visual Defaults");
    onlyVisualsCheckBox.setSelected(true);
    onlyVisualsCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            boolean showOnlyVisuals = onlyVisualsCheckBox.isSelected();
            for(int i = 0; i < tabPane.getTabCount() ; i++) {
                JScrollPane scrollpane = (JScrollPane)tabPane.getComponentAt(i);
                JTable table = (JTable)scrollpane.getViewport().getView();
                TableRowSorter sorter = (TableRowSorter)table.getRowSorter();
                sorter.setRowFilter(showOnlyVisuals? visualsFilter : null);                    
            }
        }
    });
    return onlyVisualsCheckBox;
}
 
Example #10
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private void deleteActionPerformed() {
  int[] selection = table.getSelectedRows();
  if (selection.length == 0) {
    return;
  }
  for (int i: selection) {
    int mi = table.convertRowIndexToModel(i);
    deletedRowSet.add(mi);
    SwingWorker<?, ?> worker = getSwingWorker(mi);
    if (Objects.nonNull(worker) && !worker.isDone()) {
      worker.cancel(true);
      // executor.remove(worker);
    }
    // worker = null;
  }
  RowSorter<? extends TableModel> sorter = table.getRowSorter();
  ((TableRowSorter<? extends TableModel>) sorter).setRowFilter(new RowFilter<TableModel, Integer>() {
    @Override public boolean include(Entry<? extends TableModel, ? extends Integer> entry) {
      return !deletedRowSet.contains(entry.getIdentifier());
    }
  });
  table.clearSelection();
  table.repaint();
}
 
Example #11
Source File: SBOLInputDialog.java    From iBioSim with Apache License 2.0 6 votes vote down vote up
private void updateFilter(String filterText) 
{
	filterText = "(?i)" + filterText;
	@SuppressWarnings({ "rawtypes", "unchecked" })
	TableRowSorter<TopLevelTableModel> sorter = (TableRowSorter) table.getRowSorter();
	if (filterText.length() == 0) {
		sorter.setRowFilter(null);
	} else {
		try {
			RowFilter<TopLevelTableModel, Object> rf = RowFilter.regexFilter(filterText, 0, 1);
			sorter.setRowFilter(rf);
		} catch (java.util.regex.PatternSyntaxException e) {
			sorter.setRowFilter(null);
		}
	}

	tableLabel.setText("Matching parts (" + sorter.getViewRowCount() + ")");
}
 
Example #12
Source File: ImportForm.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
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;
        }
    });
}
 
Example #13
Source File: CTrackingResultsTable.java    From binnavi with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new results tracking table.
 *
 * @param container Results container from where the results can be read.
 */
public CTrackingResultsTable(final CTrackingResultContainer container) {
  m_container =
      Preconditions.checkNotNull(container, "IE01691: Container argument can not be null");

  m_model = new CTrackingResultsTableModel(container);
  setModel(m_model);

  m_sorter = new TableRowSorter<TableModel>(m_model);
  setRowSorter(m_sorter);
  m_sorter.setComparator(ADDRESS_COLUMN, new LexicalComparator());

  // Make sure that the status cells are colored.
  getColumnModel().getColumn(STATUS_COLUMN).setCellRenderer(new CStatusColumnRenderer());
  getColumnModel().getColumn(INSTRUCTION_COLUMN).setCellRenderer(new CMonospaceRenderer());

  final InternalSelectionListener listener = new InternalSelectionListener();

  getSelectionModel().addListSelectionListener(listener);
  addMouseListener(listener);
}
 
Example #14
Source File: UmbelSearchConceptSelector.java    From wandora with GNU General Public License v3.0 6 votes vote down vote up
private void updateDataTable() {
    dataTable = new JTable();
    dataTable.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    if(data != null) {
        dataModel = new UmbelConceptTableModel(data);
        dataTable.setModel(dataModel);
        dataTable.setRowSorter(new TableRowSorter(dataModel));

        dataTable.setColumnSelectionAllowed(false);
        dataTable.setRowSelectionAllowed(true);
        dataTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

        TableColumn column = null;
        for (int i=0; i < dataTable.getColumnCount(); i++) {
            column = dataTable.getColumnModel().getColumn(i);
            column.setPreferredWidth(dataModel.getColumnWidth(i));
        }
        tableScrollPane.setViewportView(dataTable);
    }
}
 
Example #15
Source File: DefaultsDisplay.java    From beautyeye with Apache License 2.0 6 votes vote down vote up
protected void initFilters(JTable table) {
    TableRowSorter sorter = new TableRowSorter(table.getModel());
    table.setRowSorter(sorter);
    
    if (visualsFilter == null) {
        visualsFilter = new RowFilter<UIDefaultsTableModel,Integer>() {
            public boolean include(Entry<? extends UIDefaultsTableModel, ? extends Integer> entry) {
                UIDefaultsTableModel model = entry.getModel();
                Object defaultsValue = model.getValueAt(entry.getIdentifier().intValue(),
                        UIDefaultsTableModel.VALUE_COLUMN);

                return defaultsValue instanceof Color ||
                        defaultsValue instanceof Font ||
                        defaultsValue instanceof Icon;
            }
        };
    }
    
    if (onlyVisualsCheckBox.isSelected()) {
        sorter.setRowFilter(visualsFilter);
    }
}
 
Example #16
Source File: ReceiveAddressDialog.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
public ReceiveAddressDialog(JDialog parent) {
	super(parent, "Receive Addresses", Dialog.ModalityType.DOCUMENT_MODAL);
	setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
	tableModel = new AddressTableModel(columnNames, columnClasses);
	table = new AddressTable(tableModel, columnTypes);
	table.setRowSorter(new TableRowSorter<>(tableModel));
	table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	scrollPane = new JScrollPane(table);
	JPanel tablePane = new JPanel();
	tablePane.setBackground(Color.WHITE);
	tablePane.add(Box.createGlue());
	tablePane.add(scrollPane);
	tablePane.add(Box.createGlue());
	JPanel buttonPane = new ButtonPane(this, 10, new String[] { "New", "new" }, new String[] { "Copy", "copy" },
			new String[] { "Edit", "edit" }, new String[] { "Done", "done" });
	buttonPane.setBackground(Color.white);
	JPanel contentPane = new JPanel();
	contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
	contentPane.setOpaque(true);
	contentPane.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
	contentPane.setBackground(Color.WHITE);
	contentPane.add(tablePane);
	contentPane.add(buttonPane);
	setContentPane(contentPane);
}
 
Example #17
Source File: JTableEx.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void setAutoCreateRowSorter(boolean autoCreateRowSorter)
{
	boolean oldValue = this.sortingEnabled;
	this.sortingEnabled = autoCreateRowSorter;
	if (sortingEnabled)
	{
		TableModel model = getModel();
		if (model instanceof SortableTableModel)
		{
			setRowSorter(new SortableTableRowSorter((SortableTableModel) dataModel));
		}
		else
		{
			setRowSorter(new TableRowSorter<>(model));
		}
	}
	firePropertyChange("autoCreateRowSorter", oldValue, autoCreateRowSorter);
}
 
Example #18
Source File: Discrete1BandTabularForm.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
public Discrete1BandTabularForm(ColorManipulationForm parentForm) {
    this.parentForm = parentForm;
    tableModel = new ImageInfoTableModel();
    moreOptionsForm = new MoreOptionsForm(this, false);

    final JTable table = new JTable(tableModel);
    table.setRowSorter(new TableRowSorter<>(tableModel));
    table.setDefaultRenderer(Color.class, new ColorTableCellRenderer());
    table.setDefaultEditor(Color.class, new ColorTableCellEditor());
    table.getTableHeader().setReorderingAllowed(false);
    table.getColumnModel().getColumn(1).setPreferredWidth(140);
    table.getColumnModel().getColumn(3).setCellRenderer(new PercentageRenderer());

    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    final JScrollPane tableScrollPane = new JScrollPane(table);
    tableScrollPane.getViewport().setPreferredSize(table.getPreferredSize());
    contentPanel = tableScrollPane;
}
 
Example #19
Source File: EncodeTableModel.java    From Juicebox with MIT License 6 votes vote down vote up
public EncodeTableModel(String[] headings, List<EncodeFileRecord> records) {

        this.records = records;

        List<String> tmp = new ArrayList<>();
        tmp.add("");  // Checkbox heading
        for (String h : headings) {
            String heading = h.trim();
            if (heading.length() > 0 && !"path".equals(heading)) {
                tmp.add(heading);
            }
        }
        //tmp.add("path");
        columnHeadings = tmp.toArray(new String[tmp.size()]);


        sorter = new TableRowSorter<>(this);

        sorter.setStringConverter(new TableStringConverter() {
            @Override
            public String toString(TableModel model, int row, int column) {
                final Object value = model.getValueAt(row, column);
                return value == null ? "" : value.toString();
            }
        });
    }
 
Example #20
Source File: JTableEx.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void setAutoCreateRowSorter(boolean autoCreateRowSorter)
{
	boolean oldValue = this.sortingEnabled;
	this.sortingEnabled = autoCreateRowSorter;
	if (sortingEnabled)
	{
		TableModel model = getModel();
		if (model instanceof SortableTableModel)
		{
			setRowSorter(new SortableTableRowSorter((SortableTableModel) dataModel));
		}
		else
		{
			setRowSorter(new TableRowSorter<>(model));
		}
	}
	firePropertyChange("autoCreateRowSorter", oldValue, autoCreateRowSorter);
}
 
Example #21
Source File: PeakListTableWindow.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void updateFilter() {

  List<RowFilter<Object, Object>> rowSorters = new ArrayList<RowFilter<Object, Object>>();


  TableRowSorter<PeakListTableModel> sorter =
      (TableRowSorter<PeakListTableModel>) table.getRowSorter();

  String textId = "(?i)" + filterTextId.getText();
  String textIdentity = "(?i)" + filterTextIdentity.getText();
  String textComment = "(?i)" + filterTextComment.getText();

  rowSorters.add(RowFilter.regexFilter(textId, 0));
  rowSorters.add(mzFilter);
  rowSorters.add(rtFilter);
  rowSorters.add(RowFilter.regexFilter(textIdentity, 3));
  rowSorters.add(RowFilter.regexFilter(textComment, 4));

  sorter.setRowFilter(RowFilter.andFilter(rowSorters));
  table.setRowSorter(sorter);

}
 
Example #22
Source File: DefaultsDisplay.java    From littleluck with Apache License 2.0 6 votes vote down vote up
protected void initFilters(JTable table) {
    TableRowSorter sorter = new TableRowSorter(table.getModel());
    table.setRowSorter(sorter);
    
    if (visualsFilter == null) {
        visualsFilter = new RowFilter<UIDefaultsTableModel,Integer>() {
            public boolean include(Entry<? extends UIDefaultsTableModel, ? extends Integer> entry) {
                UIDefaultsTableModel model = entry.getModel();
                Object defaultsValue = model.getValueAt(entry.getIdentifier().intValue(),
                        UIDefaultsTableModel.VALUE_COLUMN);

                return defaultsValue instanceof Color ||
                        defaultsValue instanceof Font ||
                        defaultsValue instanceof Icon;
            }
        };
    }
    
    if (onlyVisualsCheckBox.isSelected()) {
        sorter.setRowFilter(visualsFilter);
    }
}
 
Example #23
Source File: TailingModeMarkersPanel.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
public TailingModeMarkersPanel(LogDataTableModel logDataTableModel) {
  super(new MigLayout("wrap 2", "[] [grow]", ""));
  this.dataTableModel = logDataTableModel;

  defaultTableModel = new SelectedMarkersTableModel();
  table = new JTable(defaultTableModel);
  table.getColumnModel().getColumn(0).setMaxWidth(16);

  TableRowSorter<SelectedMarkersTableModel> rowSorter = new TableRowSorter<>(defaultTableModel);
  MarkersRowFilter markersRowFilter = new MarkersRowFilter();
  rowSorter.setRowFilter(markersRowFilter);
  table.setRowSorter(rowSorter);
  table.setOpaque(true);
  // table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer());
  table.setDefaultRenderer(Object.class, new AutomaticMarkerRenderer());

  boxModel = new DefaultComboBoxModel();
  selectedGroup = new JComboBox(boxModel);
  selectedGroup.addActionListener(e -> defaultTableModel.fireTableDataChanged());

  logDataTableModel.addTableModelListener(this);
  markersContainser = AllPluginables.getInstance().getMarkersContainser();
  markersContainser.addListener(defaultTableModel);
  markersContainser.addListener(this);
  updateGroups(markersContainser.getElements());
  createView();

  defaultTableModel.data.addAll(markersContainser.getElements());
  defaultTableModel.fireTableDataChanged();
}
 
Example #24
Source File: ResultStatisticTab.java    From incubator-iotdb with Apache License 2.0 5 votes vote down vote up
ResultStatisticTab(String planName, Map<String, List<TimeSeriesStatistics>>
    timeseriesStatistics, TabCloseCallBack closeCallBack) {
  super(planName, closeCallBack);

  table = new JTable();

  Box box = Box.createVerticalBox();
  // the header and the data should be added separately
  box.add(table.getTableHeader());
  box.add(table);

  // provides a scroll bar for many series
  JScrollPane scrollPane = new JScrollPane(box);
  scrollPane.setLocation(0, 100);
  scrollPane.setSize(800, 600);
  add(scrollPane);

  Object[] header = TimeSeriesStatistics.HEADER;
  List<TimeSeriesStatistics> allStatistics = new ArrayList<>();
  for (List<TimeSeriesStatistics> seriesStatistics : timeseriesStatistics.values()) {
    allStatistics.addAll(seriesStatistics);
  }
  allStatistics.sort(Comparator.comparing(TimeSeriesStatistics::getName));
  Object[][] data = new Object[allStatistics.size()][];
  for (int i = 0; i < allStatistics.size(); i++) {
    data[i] = allStatistics.get(i).toArray();
  }
  tableModel = new DefaultTableModel(data, header);
  table.setModel(tableModel);
  // enable sort by column
  table.setRowSorter(new TableRowSorter<>(tableModel));
}
 
Example #25
Source File: CEventValueTable.java    From binnavi with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new table object.
 *
 * @param model The model of the table.
 */
public CEventValueTable(final CEventValueTableModel model) {
  super(model);
  m_model = model;
  setRowSorter(new TableRowSorter<CEventValueTableModel>(model));
  setFont(GuiHelper.MONOSPACED_FONT);
}
 
Example #26
Source File: PerformanceMonitor.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/** Creates new form PerformanceMonitor */
public PerformanceMonitor() {
    initComponents();
    if(Display.getInstance().getCurrent() != null) {
        refreshFrameActionPerformed(null);
    }
    resultData.setModel(new Model());
    performanceLog.setLineWrap(true);
    resultData.setRowSorter(new TableRowSorter<Model>((Model)resultData.getModel()));
}
 
Example #27
Source File: HighlightTable.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private void setSorter(TableModel model) {
    TableRowSorter<TableModel> sorter = new TableRowSorter<>(model);
    sorter.setSortsOnUpdates(true);
    LinkedList<RowSorter.SortKey> sortKeys = new LinkedList<>();
    sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
    sorter.setSortKeys(sortKeys);
    sorter.sort();
    setRowSorter(sorter);
}
 
Example #28
Source File: TextTable.java    From flowml with Apache License 2.0 5 votes vote down vote up
public void setSort(int column, SortOrder sortOrder) {
    rowSorter = new TableRowSorter<TableModel>(this.tableModel);
    List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();
    // sortKeys.add(new RowSorter.SortKey(1, SortOrder.ASCENDING));
    sortKeys.add(new RowSorter.SortKey(column, sortOrder));
    rowSorter.setSortKeys(sortKeys);
}
 
Example #29
Source File: TableViewTopComponent.java    From constellation with Apache License 2.0 5 votes vote down vote up
/**
 * Assign a new filter while keeping the sort keys.
 */
private void setNewFilter() {
    final RowSorter<? extends TableModel> oldSorter = dataTable.getRowSorter();
    final GraphTableModel gtm = (GraphTableModel) dataTable.getModel();
    final TableRowSorter<GraphTableModel> sorter = new TableRowSorter<>(gtm);
    sorter.setSortKeys(oldSorter.getSortKeys());
    if (selectedOnlyButton.isSelected()) {
        sorter.setRowFilter(new SelectionRowFilter(graphNode.getGraph(), currentElementType));
    }
    dataTable.setRowSorter(sorter);
}
 
Example #30
Source File: bug8032874.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void createAndShowUI() {
    try {
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    JFrame frame = new JFrame("bug8032874");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    tableModel = new TestTableModel();
    table = new JTable(tableModel);
    table.setSurrendersFocusOnKeystroke(true);

    final TableRowSorter<TestTableModel> rowSorter = new TableRowSorter<TestTableModel>(tableModel);
    rowSorter.setRowFilter(new RowFilter<TestTableModel, Integer>() {
        @Override
        public boolean include(Entry<? extends TestTableModel, ? extends Integer> entry) {
            return entry.getIdentifier() % 2 == 0;
        }
    });
    table.setRowSorter(rowSorter);

    JScrollPane jScrollPane = new JScrollPane(table);
    panel.add(jScrollPane);

    frame.setContentPane(panel);
    frame.setSize(new Dimension(800, 600));
    frame.setVisible(true);
}