List of usage examples for javax.swing JTable getSelectedRowCount
@BeanProperty(bound = false) public int getSelectedRowCount()
From source file:org.zaproxy.zap.extension.multiFuzz.impl.http.HttpFuzzResultDialog.java
@Override public JXTreeTable getTable() { if (table == null) { if (model == null) { model = new HttpFuzzTableModel(); }/*from w w w. ja v a2 s.com*/ table = new JXTreeTable(model); table.setDoubleBuffered(true); table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION); table.setName("HttpFuzzResultTable"); table.setFont(new java.awt.Font("Default", java.awt.Font.PLAIN, 12)); table.setDefaultRenderer(Pair.class, new IconTableCellRenderer()); int[] widths = { 10, 25, 550, 30, 85, 55, 40, 70 }; for (int i = 0, count = widths.length; i < count; i++) { TableColumn column = table.getColumnModel().getColumn(i); column.setPreferredWidth(widths[i]); } table.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mousePressed(java.awt.event.MouseEvent e) { showPopupMenuIfTriggered(e); } @Override public void mouseReleased(java.awt.event.MouseEvent e) { showPopupMenuIfTriggered(e); } private void showPopupMenuIfTriggered(java.awt.event.MouseEvent e) { if (e.isPopupTrigger()) { if (e.isPopupTrigger()) { // Select list item on right click JTable table = (JTable) e.getSource(); int row = table.rowAtPoint(e.getPoint()); if (!table.isRowSelected(row)) { table.changeSelection(row, 0, false, false); } View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY()); } } } }); table.getSelectionModel().addListSelectionListener(new javax.swing.event.ListSelectionListener() { @Override public void valueChanged(javax.swing.event.ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { if (table.getSelectedRowCount() == 0) { return; } final int row = table.getSelectedRow(); if (getEntry(row) instanceof HttpFuzzRequestRecord) { final HistoryReference historyReference = ((HttpFuzzRequestRecord) getEntry(row)) .getHistory(); try { getMessageInspection().setMessage(historyReference.getHttpMessage()); } catch (HttpMalformedHeaderException | SQLException ex) { logger.error(ex.getMessage(), ex); } } updateValues(); redrawDiagrams(); } } }); } table.getTableHeader().addMouseListener(new MouseListener() { int sortedOn = -1; @Override public void mouseReleased(MouseEvent arg0) { } @Override public void mousePressed(MouseEvent arg0) { } @Override public void mouseExited(MouseEvent arg0) { } @Override public void mouseEntered(MouseEvent arg0) { } @Override public void mouseClicked(MouseEvent e) { int index = table.columnAtPoint(e.getPoint()); List<HttpFuzzRecord> list = model.getEntries(); if (list.size() == 0) { return; } HttpFuzzRecordComparator comp = new HttpFuzzRecordComparator(); comp.setFeature(index); if (index == sortedOn) { Collections.sort(list, comp); Collections.reverse(list); sortedOn = -1; } else { Collections.sort(list, comp); sortedOn = index; } table.updateUI(); } }); table.setRootVisible(false); table.setVisible(true); return table; }
From source file:gtu._work.mvn.MavenRepositoryUI.java
private void tableMouseClicked(JTable table, int pomFileColPos, MouseEvent evt) { //?//from ww w. jav a 2 s . c om if (table.getSelectedRowCount() > 1) { int realRowPos = -1; PomFile pomFile = null; List<PomFile> list = new ArrayList<PomFile>(); for (int rowPos : table.getSelectedRows()) { realRowPos = table.getRowSorter().convertRowIndexToModel(rowPos); pomFile = (PomFile) table.getModel().getValueAt(realRowPos, pomFileColPos); list.add(pomFile); } defaultPopupMenu(list, table, evt); return; } //? Object selectValue = JTableUtil.newInstance(table).getSelectedValue(); int rowIndex = JTableUtil.newInstance(table).getSelectedRow(); PomFile pomFile = (PomFile) table.getModel().getValueAt(rowIndex, pomFileColPos); ClipboardUtil.getInstance().setContents(selectValue); if (JMouseEventUtil.buttonRightClick(1, evt)) { this.defaultPopupMenu(Arrays.asList(pomFile), table, evt); } if (JMouseEventUtil.buttonLeftClick(2, evt)) { this.showPomInfo(pomFile); } }
From source file:net.sourceforge.squirrel_sql.fw.gui.action.wikiTable.GenericWikiTableTransformer.java
/** * @see/*from w ww . ja va2 s. c o m*/ * net.sourceforge.squirrel_sql.fw.gui.action.wikiTable.IWikiTableTransformer * #transform(javax.swing.JTable) */ @Override public String transform(JTable table) { int nbrSelRows = table.getSelectedRowCount(); int nbrSelCols = table.getSelectedColumnCount(); int[] selRows = table.getSelectedRows(); int[] selCols = table.getSelectedColumns(); if (selRows.length != 0 && selCols.length != 0) { StringBuilder buf = new StringBuilder(1024); // Start the table appendWithReplacement(buf, configuration.getTableStartTag()); // Create the header appendWithReplacement(buf, configuration.getHeaderStartTag()); for (int colIdx = 0; colIdx < nbrSelCols; ++colIdx) { appendWithReplacement(buf, configuration.getHeaderCell(), table.getColumnName(selCols[colIdx])); } appendWithReplacement(buf, configuration.getHeaderEndTag()); // Now fill all the table rows for (int rowIdx = 0; rowIdx < nbrSelRows; ++rowIdx) { appendWithReplacement(buf, configuration.getRowStartTag()); for (int colIdx = 0; colIdx < nbrSelCols; ++colIdx) { TableCellRenderer cellRenderer = table.getCellRenderer(selRows[rowIdx], selCols[colIdx]); Object cellObj = table.getValueAt(selRows[rowIdx], selCols[colIdx]); if (cellRenderer instanceof SquirrelTableCellRenderer) { cellObj = ((SquirrelTableCellRenderer) cellRenderer).renderValue(cellObj); } String value = null; if (cellObj == null) { value = ""; //$NON-NLS-1$ } else { final String tmp = cellObj.toString(); if (tmp.trim().equals("")) { //$NON-NLS-1$ value = ""; //$NON-NLS-1$ } else { value = tmp; } } appendWithReplacement(buf, configuration.getDataCell(), value); } appendWithReplacement(buf, configuration.getRowEndTag()); } appendWithReplacement(buf, configuration.getTableEndTag()); return buf.toString(); } else { return null; } }
From source file:nz.govt.natlib.ndha.manualdeposit.jobmanagement.JobQueueManagement.java
public JPopupMenu getJobQueueMenu(final JTable table) { theTableSelected = table;/*from w w w. j a v a 2 s . c o m*/ final JPopupMenu menu = new JPopupMenu(); boolean sortAscending = false; if (table.equals(theJobQueueRunningTable)) { sortAscending = personalSettings.isSortRunningAscending(); } else if (table.equals(theJobQueuePendingTable)) { sortAscending = personalSettings.isSortPendingAscending(); } else if (table.equals(theJobQueueFailedTable)) { sortAscending = personalSettings.isSortFailedAscending(); } else if (table.equals(theJobQueueDepositedTable)) { sortAscending = personalSettings.isSortDepositedAscending(); } else if (table.equals(theJobQueueInPermanentTable)) { sortAscending = personalSettings.isSortCompleteAscending(); } JMenuItem item; if (sortAscending) { item = new JMenuItem("Sort by date in descending order"); } else { item = new JMenuItem("Sort by date in ascending order"); } item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { resortTable(evt); } }); menu.add(item); if ((table.equals(theJobQueueRunningTable)) || (table.equals(theJobQueuePendingTable)) || (table.equals(theJobQueueFailedTable))) { StringBuffer text = new StringBuffer(); text.append("Cancel job"); if (table.getSelectedRowCount() > 1) { text.append('s'); } item = new JMenuItem(text.toString()); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { try { cancelJobs(evt); } catch (JobQueueException ex) { String message = "Error cancelling jobs"; LOG.error(message, ex); mainFrame.showError("An error occurred", message, ex); } } }); menu.add(item); if (table.equals(theJobQueueFailedTable)) { text = new StringBuffer(); text.append("Resubmit job"); if (table.getSelectedRowCount() > 1) { text.append('s'); } item = new JMenuItem(text.toString()); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { resubmitJob(evt); } }); menu.add(item); } } if (table.equals(theJobQueueInPermanentTable)) { item = new JMenuItem("Clear completed jobs"); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { clearFinishedJobs(evt); } }); menu.add(item); } if (menu == null || menu.getComponentCount() == 0) { return null; } else { return menu; } }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositMain.java
private void jobQueueMousePressedCommon(java.awt.event.MouseEvent evt, JTable table) { if (evt.isPopupTrigger()) { if (table.getSelectedRowCount() == 0) { int row = table.rowAtPoint(evt.getPoint()); if (row > -1) { table.setRowSelectionInterval(row, row); }/*from w w w . jav a 2 s . com*/ } JPopupMenu menu = depositPresenter.getJobQueueMenu((JTable) evt.getSource()); if (menu != null) { menu.show(evt.getComponent(), evt.getX(), evt.getY()); } } }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositMain.java
private void jobQueueMouseReleaseCommon(java.awt.event.MouseEvent evt, JTable table) { if (evt.isPopupTrigger()) { if (table.getSelectedRowCount() == 0) { int row = table.rowAtPoint(evt.getPoint()); if (row > -1) { table.setRowSelectionInterval(row, row); }/* w w w.j a va 2 s. c om*/ } JPopupMenu menu = depositPresenter.getJobQueueMenu((JTable) evt.getSource()); if (menu != null) { menu.show(evt.getComponent(), evt.getX(), evt.getY()); } } }
From source file:org.rdv.datapanel.DigitalTabularDataPanel.java
private void addColumn() { if (columnGroupCount == MAX_COLUMN_GROUP_COUNT) { return;//from w w w .j a v a 2 s. co m } if (columnGroupCount != 0) { panelBox.add(Box.createHorizontalStrut(7)); } final int tableIndex = columnGroupCount; final DataTableModel tableModel = new DataTableModel(); final JTable table = new JTable(tableModel); table.setDragEnabled(true); table.setName(DigitalTabularDataPanel.class.getName() + " JTable #" + Integer.toString(columnGroupCount)); if (showThresholdCheckBoxGroup.isSelected()) { tableModel.setThresholdVisible(true); } if (showMinMaxCheckBoxGroup.isSelected()) { tableModel.setMaxMinVisible(true); table.getColumn("Min").setCellRenderer(doubleCellRenderer); table.getColumn("Max").setCellRenderer(doubleCellRenderer); } table.getColumn("Value").setCellRenderer(dataCellRenderer); tables.add(table); tableModels.add(tableModel); JScrollPane tableScrollPane = new JScrollPane(table); panelBox.add(tableScrollPane); // popup menu for panel JPopupMenu popupMenu = new JPopupMenu(); final JMenuItem copyMenuItem = new JMenuItem("Copy"); copyMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { TransferHandler.getCopyAction().actionPerformed( new ActionEvent(table, ae.getID(), ae.getActionCommand(), ae.getWhen(), ae.getModifiers())); } }); popupMenu.add(copyMenuItem); popupMenu.addSeparator(); JMenuItem printMenuItem = new JMenuItem("Print..."); printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { table.print(JTable.PrintMode.FIT_WIDTH); } catch (PrinterException pe) { } } }); popupMenu.add(printMenuItem); popupMenu.addSeparator(); final JCheckBoxMenuItem showMaxMinMenuItem = new JCheckBoxMenuItem("Show min/max columns", false); showMaxMinMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setMaxMinVisible(showMaxMinMenuItem.isSelected()); } }); showMinMaxCheckBoxGroup.addCheckBox(showMaxMinMenuItem); popupMenu.add(showMaxMinMenuItem); final JCheckBoxMenuItem showThresholdMenuItem = new JCheckBoxMenuItem("Show threshold columns", false); showThresholdMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setThresholdVisible(showThresholdMenuItem.isSelected()); } }); showThresholdCheckBoxGroup.addCheckBox(showThresholdMenuItem); popupMenu.add(showThresholdMenuItem); popupMenu.addSeparator(); JMenuItem blankRowMenuItem = new JMenuItem("Insert blank row"); blankRowMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tableModel.addBlankRow(); } }); popupMenu.add(blankRowMenuItem); final JMenuItem removeSelectedRowsMenuItem = new JMenuItem("Remove selected rows"); removeSelectedRowsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { removeSelectedRows(tableIndex); } }); popupMenu.add(removeSelectedRowsMenuItem); popupMenu.addSeparator(); JMenu numberOfColumnsMenu = new JMenu("Number of columns"); numberOfColumnsMenu.addMenuListener(new MenuListener() { public void menuSelected(MenuEvent me) { JMenu menu = (JMenu) me.getSource(); for (int j = 0; j < MAX_COLUMN_GROUP_COUNT; j++) { JMenuItem menuItem = menu.getItem(j); boolean selected = (j == (columnGroupCount - 1)); menuItem.setSelected(selected); } } public void menuDeselected(MenuEvent me) { } public void menuCanceled(MenuEvent me) { } }); for (int i = 0; i < MAX_COLUMN_GROUP_COUNT; i++) { final int number = i + 1; JRadioButtonMenuItem item = new JRadioButtonMenuItem(Integer.toString(number)); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setNumberOfColumns(number); } }); numberOfColumnsMenu.add(item); } popupMenu.add(numberOfColumnsMenu); popupMenu.addPopupMenuListener(new PopupMenuListener() { public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) { boolean anyRowsSelected = table.getSelectedRowCount() > 0; copyMenuItem.setEnabled(anyRowsSelected); removeSelectedRowsMenuItem.setEnabled(anyRowsSelected); } public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) { } public void popupMenuCanceled(PopupMenuEvent arg0) { } }); // set component popup and mouselistener to trigger it table.setComponentPopupMenu(popupMenu); tableScrollPane.setComponentPopupMenu(popupMenu); panelBox.revalidate(); columnGroupCount++; properties.setProperty("numberOfColumns", Integer.toString(columnGroupCount)); }
From source file:org.simmi.GeneSetHead.java
License:asdf
public void updateFilter(JTable table, RowFilter filter, Label label) { DefaultRowSorter<TableModel, Integer> rowsorter = (DefaultRowSorter<TableModel, Integer>) table .getRowSorter();//from w ww. ja v a2 s . co m rowsorter.setRowFilter(filter); if (label != null) label.setText(table.getRowCount() + "/" + table.getSelectedRowCount()); }