List of usage examples for javax.swing JTable rowAtPoint
public int rowAtPoint(Point point)
point
lies in, or -1 if the result is not in the range [0, getRowCount()
-1]. From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewer.java
private void setupTable() { tableModel = new ElementListTableModel(); table = new JXTable(tableModel); tableSorter = new ElementListTableSorter(tableModel, table); table.getTableHeader().addMouseListener(tableSorter); // add sorter & header renderer table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true);/* w w w. jav a 2s.c o m*/ // set our column widths ElementListTableModel.setupColumnWidths(table); table.setDefaultRenderer(Object.class, new ElementListCellRenderer(this, false)); table.setDefaultRenderer(Boolean.class, new BooleanCellRenderer(this, false)); // hide irrelevent columns TableColumnModelExt colmodel = (TableColumnModelExt) table.getColumnModel(); table.setColumnControlVisible(true); colmodel.getColumnExt(I18n.getText("hidden.MostRecentVersion")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.n")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.rec")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.hash")).setVisible(false); // popup menu table.addMouseListener(new PopupListener() { @Override public void showPopup(MouseEvent e) { // only clicks on tables if (!(e.getSource() instanceof JTable)) return; JTable table = (JTable) e.getSource(); ElementListTableModel model = (ElementListTableModel) table.getModel(); // get the row and sanity check int row = table.rowAtPoint(e.getPoint()); if (row < 0 || row >= model.getRowCount()) return; // select it? table.setRowSelectionInterval(row, row); // get the element Element element = model.getElementAt(row); // create and show the menu JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewer.this); popup.show(table, e.getX(), e.getY()); } }); }
From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewerOld.java
private void setupTable() { tableModel = new ElementListTableModel(); table = new JXTable(tableModel); tableSorter = new ElementListTableSorter(tableModel, table); table.getTableHeader().addMouseListener(tableSorter); // add sorter & header renderer table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true);/*w w w. j av a 2 s . c om*/ // set our column widths ElementListTableModel.setupColumnWidths(table); table.setDefaultRenderer(Object.class, new ElementListCellRenderer(this, false)); table.setDefaultRenderer(Boolean.class, new BooleanCellRenderer(this, false)); // hide irrelevent columns TableColumnModelExt colmodel = (TableColumnModelExt) table.getColumnModel(); table.setColumnControlVisible(true); colmodel.getColumnExt(I18n.getText("hidden.MostRecentVersion")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.n")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.rec")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.hash")).setVisible(false); // popup menu table.addMouseListener(new PopupListener() { @Override public void showPopup(MouseEvent e) { // only clicks on tables if (!(e.getSource() instanceof JTable)) return; JTable table = (JTable) e.getSource(); ElementListTableModel model = (ElementListTableModel) table.getModel(); // get the row and sanity check int row = table.rowAtPoint(e.getPoint()); if (row < 0 || row >= model.getRowCount()) return; // select it? table.setRowSelectionInterval(row, row); // get the element Element element = model.getElementAt(row); // create and show the menu JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewerOld.this); popup.show(table, e.getX(), e.getY()); } }); }
From source file:org.tmpotter.ui.ActionHandler.java
public void onTableClicked(MouseEvent evt) { javax.swing.JTable table = (javax.swing.JTable) evt.getSource(); Point point = evt.getPoint(); int row = table.rowAtPoint(point); int col = table.columnAtPoint(point); table.setRowSelectionInterval(row, row); table.setColumnSelectionInterval(col, col); tmData.setPositionTextArea(0);/*ww w.j a v a 2 s. c o m*/ if (tmData.getIndexPrevious() < tmData.getDocumentOriginalSize()) { tmData.setOriginalDocumentAnt(restoreText(modelMediator.getLeftEdit())); tmData.setTranslationDocumentAnt(restoreText(modelMediator.getRightEdit())); } modelMediator.setLeftEdit(formatText(modelMediator.getLeftSegment(modelMediator.getTmViewSelectedRow()))); modelMediator.setRightEdit(formatText(modelMediator.getRightSegment(modelMediator.getTmViewSelectedRow()))); tmData.setBothIndex(modelMediator.getTmViewSelectedRow()); if (tmData.isIdentTop()) { modelMediator.setJoinEnabled(false); } else { modelMediator.setJoinEnabled(true); } modelMediator.updateTmView(); }
From source file:org.zaproxy.zap.extension.multiFuzz.impl.http.HttpFuzzerContentPanel.java
public JXTreeTable getFuzzResultTable() { if (fuzzResultTable == null) { resetFuzzResultTable();/*from w w w . j a v a 2s. co m*/ fuzzResultTable = new JXTreeTable(getResultsModel()); fuzzResultTable.setName("HttpFuzzResultTable"); fuzzResultTable.setDoubleBuffered(true); fuzzResultTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION); fuzzResultTable.setFont(new java.awt.Font("Default", java.awt.Font.PLAIN, 12)); fuzzResultTable.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 = fuzzResultTable.getColumnModel().getColumn(i); column.setPreferredWidth(widths[i]); } fuzzResultTable.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() && SwingUtilities.isRightMouseButton(e)) { // 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()); } } }); fuzzResultTable.getSelectionModel() .addListSelectionListener(new javax.swing.event.ListSelectionListener() { @Override public void valueChanged(javax.swing.event.ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { if (fuzzResultTable.getSelectedRowCount() == 0) { return; } final int row = fuzzResultTable.getSelectedRow(); if (getEntry(row) instanceof HttpFuzzRequestRecord) { final HistoryReference historyReference = ((HttpFuzzRequestRecord) getEntry( row)).getHistory(); try { displayMessage(historyReference.getHttpMessage()); } catch (HttpMalformedHeaderException | SQLException ex) { logger.error(ex.getMessage(), ex); } } } } }); fuzzResultTable.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 = fuzzResultTable.columnAtPoint(e.getPoint()); List<HttpFuzzRecord> list = getResultsModel().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; } fuzzResultTable.updateUI(); } }); fuzzResultTable.setRootVisible(false); fuzzResultTable.setVisible(true); } return fuzzResultTable; }
From source file:pcgen.gui2.tabs.EquipInfoTab.java
private List<Integer> getMenuTargets(JTable table, MouseEvent e) { int row = table.rowAtPoint(e.getPoint()); if (!table.isRowSelected(row)) { table.setRowSelectionInterval(row, row); }//from w w w. j a v a 2 s . c o m List<Integer> targets = new ArrayList<>(); for (int selRow : table.getSelectedRows()) { targets.add(selRow); } return targets; }