private static int preferredWidth(JTable table, int col) { TableColumn tableColumn = table.getColumnModel().getColumn(col); int width = (int) table .getTableHeader() .getDefaultRenderer() .getTableCellRendererComponent( table, tableColumn.getIdentifier(), false, false, -1, col) .getPreferredSize() .getWidth(); if (table.getRowCount() != 0) { int from = 0, to = 0; Rectangle rect = table.getVisibleRect(); from = table.rowAtPoint(rect.getLocation()); to = table.rowAtPoint(new Point((int) rect.getMaxX(), (int) rect.getMaxY())) + 1; for (int row = from; row < to; row++) { int preferedWidth = (int) table .getCellRenderer(row, col) .getTableCellRendererComponent( table, table.getValueAt(row, col), false, false, row, col) .getPreferredSize() .getWidth(); width = Math.max(width, preferedWidth); } } return width + table.getIntercellSpacing().width; }
@Override public void mouseClicked(MouseEvent e) { JTable table = (JTable) e.getSource(); Point point = e.getPoint(); int clickedRow = table.rowAtPoint(point); int clickedCol = table.columnAtPoint(point); if ((clickedCol == -1) || (clickedRow == -1)) { return; } if (table.getValueAt(clickedRow, clickedCol) instanceof StringUrl) { // retrieve the link to go to String sUrl = ((StringUrl) table.getValueAt(clickedRow, clickedCol)).getUrl(); URL url; try { url = new URL(sUrl); log.debug("showing url for " + url); HtmlBrowser.URLDisplayer.getDefault().showURL(url); // prevent this from getting called again as it works it's way up the component stack e.consume(); } catch (MalformedURLException ex) { StatusBar.getInstance() .setStatusText("\"" + sUrl + "\" is not a valid URL. Cannot open in browser."); log.warn( "\"" + sUrl + "\" is not a valid URL. Cannot open in browser.\n\n" + ex.getLocalizedMessage()); } } }
public void mousePressed(MouseEvent e) { if (e.getButton() != MouseEvent.BUTTON1) { return; } if (e.getClickCount() != 2) { return; } JTable table = (JTable) e.getSource(); Point p = e.getPoint(); int row = table.rowAtPoint(p); if (row < 0) { return; } FinderTableModel model = getDataModel(); ICFSecurityISOTimezoneObj o = (ICFSecurityISOTimezoneObj) model.getValueAt(row, COLID_ROW_HEADER); if (o == null) { return; } JInternalFrame frame = swingSchema.getISOTimezoneFactory().newViewEditJInternalFrame(o); ((ICFSecuritySwingISOTimezoneJPanelCommon) frame).setPanelMode(CFJPanel.PanelMode.View); if (frame == null) { return; } Container cont = getParent(); while ((cont != null) && (!(cont instanceof JInternalFrame))) { cont = cont.getParent(); } if (cont != null) { JInternalFrame myInternalFrame = (JInternalFrame) cont; myInternalFrame.getDesktopPane().add(frame); frame.setVisible(true); frame.show(); } }
public void mousePressed(MouseEvent e) { if (e.getButton() != MouseEvent.BUTTON1) { return; } if (e.getClickCount() != 2) { return; } JTable table = (JTable) e.getSource(); Point p = e.getPoint(); int row = table.rowAtPoint(p); if (row < 0) { return; } PickerTableModel model = getDataModel(); ICFInternetISOCountryObj o = (ICFInternetISOCountryObj) model.getValueAt(row, COLID_ROW_HEADER); invokeWhenChosen.choseISOCountry(o); try { Container cont = getParent(); while ((cont != null) && (!(cont instanceof JInternalFrame))) { cont = cont.getParent(); } if (cont != null) { ((JInternalFrame) cont).setClosed(true); } } catch (Exception x) { } }
@Override public void mousePressed(MouseEvent me) { JTable table = (JTable) me.getSource(); Point p = me.getPoint(); int row = table.rowAtPoint(p); if (me.getClickCount() == 2) { int fila = grid.getSelectedRow(); System.out.println("Seleccionada " + grid.getSelectedRow()); if (grid.getModel().getValueAt(fila, 1) != null) { String openFile = grid.getModel().getValueAt(fila, 1).toString(); System.out.println("Abrir:" + openFile); if (new File(openFile).exists()) { if (Desktop.isDesktopSupported()) { try { File myFile = new File(openFile); Desktop.getDesktop().open(myFile); } catch (IOException ex) { JOptionPane.showMessageDialog( SiSeOnFrame.this, "No fue posible abrir el archivo.", "Archivo no encontrado o dañado.", JOptionPane.WARNING_MESSAGE); } } else { System.out.println("DESKTOP NO SOPORTADO"); } // if } else { JOptionPane.showMessageDialog( SiSeOnFrame.this, "El archivo ya no se encuentra en la ruta donde fue indexado."); } } } }
@Override public void mouseMoved(MouseEvent e) { Point pt = e.getPoint(); int prevRow = row; int prevCol = col; row = table.rowAtPoint(pt); col = table.columnAtPoint(pt); if (row < 0 || col < 0) { row = -1; col = -1; } // >>>> HyperlinkCellRenderer.java // @see // http://java.net/projects/swingset3/sources/svn/content/trunk/SwingSet3/src/com/sun/swingset3/demos/table/HyperlinkCellRenderer.java if (row == prevRow && col == prevCol) { return; } Rectangle repaintRect; if (row >= 0 && col >= 0) { Rectangle r = table.getCellRect(row, col, false); if (prevRow >= 0 && prevCol >= 0) { repaintRect = r.union(table.getCellRect(prevRow, prevCol, false)); } else { repaintRect = r; } } else { repaintRect = table.getCellRect(prevRow, prevCol, false); } table.repaint(repaintRect); // <<<< // table.repaint(); }
@Override protected void showPopupMenu(MouseEvent ev) { // first select/deselect the row: int iRow = tblTasks.rowAtPoint(ev.getPoint()); // Nur, wenn nicht selektiert, selektieren: if (!tblTasks.isRowSelected(iRow)) { if ((ev.getModifiers() & MouseEvent.CTRL_MASK) != 0) { // Control gedr\u00fcckt: // Zeile zur Selektion hinzuf\u00fcgen: tblTasks.addRowSelectionInterval(iRow, iRow); } else { // Sonst nur diese Zeile selektieren: tblTasks.setRowSelectionInterval(iRow, iRow); } } // if // enable/disable menu items final int iSelectedRow = this.tblTasks.getSelectedRow(); final TimelimitTaskTableModel model = timelimittaskview.getTimelimitTaskTableModel(); model.getTimelimitTask(iSelectedRow); // todo: there should be a better place for that... final boolean bPerformEnabled = existsRelatedObjectsFor(getSelectedTimelimitTasks(timelimittaskview)); actPerformTask.setEnabled(bPerformEnabled); // this.popupTimelimitTasks.miPerform.setEnabled(bPerformEnabled); final boolean bFinished = areTasksCompleted(getSelectedTimelimitTasks(timelimittaskview)); this.popupTimelimitTasks.miFinish.setState(bFinished); super.showPopupMenu(ev); }
protected Rectangle getCellRect(JTable table, Point location) { int row = table.rowAtPoint(location); int column = table.columnAtPoint(location); if (row < 0 || column < 0) return null; return table.getCellRect(row, column, true); }
/* * (non-Javadoc) * * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) */ public void mousePressed(MouseEvent e) { int row = charTable.rowAtPoint(e.getPoint()); charTable.setRowSelectionInterval(row, row); parent.setEditingChar(row); if (e.getButton() == MouseEvent.BUTTON3) { popup.show(charTable, e.getX(), e.getY()); } }
protected DrawingState getDrawingState(JTable table, Point location) { int row = table.rowAtPoint(location); int column = table.columnAtPoint(location); if (row < 0 || column < 0) return null; Object value = table.getValueAt(row, column); return value instanceof DrawingState ? (DrawingState) value : null; }
public void mousePressed(MouseEvent e) { if (e.getButton() != MouseEvent.BUTTON1) { return; } if (e.getClickCount() != 2) { return; } JTable table = (JTable) e.getSource(); Point p = e.getPoint(); int row = table.rowAtPoint(p); if (row < 0) { return; } ListTableModel model = getDataModel(); ICFInternetVersionObj o = (ICFInternetVersionObj) model.getValueAt(row, COLID_ROW_HEADER); if (o == null) { return; } JInternalFrame frame = null; String classCode = o.getClassCode(); if (classCode.equals("VERN")) { frame = swingSchema.getVersionFactory().newViewEditJInternalFrame(o); frame.addInternalFrameListener(getViewEditInternalFrameListener()); ((ICFInternetSwingVersionJPanelCommon) frame).setPanelMode(CFJPanel.PanelMode.View); } else if (classCode.equals("MJVR")) { frame = swingSchema .getMajorVersionFactory() .newViewEditJInternalFrame((ICFInternetMajorVersionObj) o); frame.addInternalFrameListener(getViewEditInternalFrameListener()); ((ICFInternetSwingMajorVersionJPanelCommon) frame).setPanelMode(CFJPanel.PanelMode.View); } else if (classCode.equals("MNVR")) { frame = swingSchema .getMinorVersionFactory() .newViewEditJInternalFrame((ICFInternetMinorVersionObj) o); frame.addInternalFrameListener(getViewEditInternalFrameListener()); ((ICFInternetSwingMinorVersionJPanelCommon) frame).setPanelMode(CFJPanel.PanelMode.View); } else { frame = null; } if (frame == null) { return; } Container cont = getParent(); while ((cont != null) && (!(cont instanceof JInternalFrame))) { cont = cont.getParent(); } if (cont != null) { JInternalFrame myInternalFrame = (JInternalFrame) cont; myInternalFrame.getDesktopPane().add(frame); frame.setVisible(true); frame.show(); } }
protected void internalDoubleClick(MouseEvent e) { if (!(e.getComponent() instanceof JComponent)) return; JComponent inComponent = (JComponent) e.getComponent(); if (inComponent instanceof JTable) { JTable thisTable = (JTable) inComponent; int rowPoint = thisTable.rowAtPoint(new Point(e.getX(), e.getY())); Searcher whichSearch = (Searcher) thisTable.getValueAt(rowPoint, -1); whichSearch.execute(); } }
protected void selectEditor(MouseEvent e) { int row; if (e == null) { row = table.getSelectionModel().getAnchorSelectionIndex(); } else { row = table.rowAtPoint(e.getPoint()); } editor = (TableCellEditor) editors.get(new Integer(row)); if (editor == null) { editor = defaultEditor; } }
@Nullable private SvnFileRevision getSelectedRevision(final MouseEvent e) { JTable table = (JTable) e.getSource(); int row = table.rowAtPoint(e.getPoint()); int column = table.columnAtPoint(e.getPoint()); final Object value = table.getModel().getValueAt(row, column); if (value instanceof SvnFileRevision) { return (SvnFileRevision) value; } return null; }
private void paintSections(Graphics g) { int rmin, rmax, rh = table.getRowHeight(); MatchTableModel model = (MatchTableModel) table.getModel(); g.getClipBounds(srect); spoint.setLocation(0, srect.y); rmin = table.rowAtPoint(spoint); if (rmin < 0) rmin = 0; spoint.setLocation(0, srect.y + srect.height); rmax = table.rowAtPoint(spoint); if (rmax < 0) rmax = table.getRowCount() - 1; for (int i = rmin; i <= rmax; i++) { if (model.isRowHeader(i)) { if (model.isRowHeader2(i)) { g.clearRect(0, rh * i, table.getWidth(), rh - 1); g.drawString( model.getDescription(i), 1, rh * i + table.getFontMetrics(table.getFont()).getAscent()); } else g.clearRect(0, rh * i, table.getWidth(), rh * 2 - 1); } } }
@Override public boolean isCellEditable(EventObject event) { if (event instanceof MouseEvent) { MouseEvent mouseEvent = (MouseEvent) event; if (mouseEvent.getClickCount() == 2) { return false; } if (mouseEvent.getClickCount() == 1 && myTable.rowAtPoint(mouseEvent.getPoint()) == myTable.getSelectedRow() && myTable.columnAtPoint(mouseEvent.getPoint()) == myTable.getSelectedColumn()) { return myProxiedEditor.isCellEditable(null); } } return myProxiedEditor.isCellEditable(event); }
protected void showPopup(MouseEvent e) { JTable source = (JTable) e.getSource(); int row = source.rowAtPoint(e.getPoint()); int column = source.columnAtPoint(e.getPoint()); if (!source.isRowSelected(row)) { source.changeSelection(row, column, false, false); } final int rowindex = source.convertRowIndexToModel(row); JPopupMenu popupMenu = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(Bundle.getMessage("CopyName")); menuItem.addActionListener( (ActionEvent e1) -> { copyName(rowindex, 0); }); popupMenu.add(menuItem); menuItem = new JMenuItem(Bundle.getMessage("Rename")); menuItem.addActionListener( (ActionEvent e1) -> { renameBean(rowindex, 0); }); popupMenu.add(menuItem); menuItem = new JMenuItem(Bundle.getMessage("Clear")); menuItem.addActionListener( (ActionEvent e1) -> { removeName(rowindex, 0); }); popupMenu.add(menuItem); menuItem = new JMenuItem(Bundle.getMessage("Move")); menuItem.addActionListener( (ActionEvent e1) -> { moveBean(rowindex, 0); }); popupMenu.add(menuItem); menuItem = new JMenuItem(Bundle.getMessage("Delete")); menuItem.addActionListener( (ActionEvent e1) -> { deleteBean(rowindex, 0); }); popupMenu.add(menuItem); popupMenu.show(e.getComponent(), e.getX(), e.getY()); }
@Override public void mouseClicked(MouseEvent e) { int col = table.columnAtPoint(new Point(e.getX(), e.getY())); String header = table.getColumnName(col); if (columnHeader.contains(header)) { int row = table.rowAtPoint(new Point(e.getX(), e.getY())); TableModel tableModel = table.getModel(); Object val = tableModel.getValueAt( table.convertRowIndexToModel(row), table.convertColumnIndexToModel(col)); if (val != null) { String text = val.toString(); textDialog.setText(text); textDialog.setVisible(true); } } }
private void paintStripedBackground(Graphics g) { // get the row index at the top of the clip bounds (the first row // to paint). int rowAtPoint = fTable.rowAtPoint(g.getClipBounds().getLocation()); // get the y coordinate of the first row to paint. if there are no // rows in the table, start painting at the top of the supplied // clipping bounds. int topY = rowAtPoint < 0 ? g.getClipBounds().y : fTable.getCellRect(rowAtPoint, 0, true).y; // create a counter variable to hold the current row. if there are no // rows in the table, start the counter at 0. int currentRow = rowAtPoint < 0 ? 0 : rowAtPoint; while (topY < g.getClipBounds().y + g.getClipBounds().height) { int bottomY = topY + fTable.getRowHeight(); g.setColor(getRowColor(currentRow)); g.fillRect(g.getClipBounds().x, topY, g.getClipBounds().width, bottomY); topY = bottomY; currentRow++; } }
private void maybeShowPopup(MouseEvent e) { if (e.isPopupTrigger() && table.isEnabled()) { currentPoint = new Point(e.getX(), e.getY()); curCol = table.columnAtPoint(currentPoint); curRow = table.rowAtPoint(currentPoint); if (curRow < 0 || curRow >= table.getRowCount()) { return; } // translate table index to model index int mcol = table.getColumn(table.getColumnName(curCol)).getModelIndex(); logger.debug("curRow, mcol" + curRow + " " + mcol); // .. create popup menu... JPopupMenu contextMenu = createContextMenu(curRow, mcol); // ... and show it if (contextMenu != null && contextMenu.getComponentCount() > 0) { contextMenu.show(table, currentPoint.x, currentPoint.y); } } }
public static void ScrollToLine(JScrollPane scrollPane, JTable table) { Rectangle vr = table.getVisibleRect(); int first = table.rowAtPoint(vr.getLocation()); Rectangle cellRect = table.getCellRect(first + 1, 0, true); JViewport viewport = scrollPane.getViewport(); Rectangle rr = viewport.getViewRect(); int shift = cellRect.y - rr.y; // String tt; // tt = String.format("%d %d %d",cellRect.y, rr.y, shift); for (int i = 0; i < shift; i++) { int cur = scrollPane.getVerticalScrollBar().getValue(); scrollPane.getVerticalScrollBar().setValue(cur + 1); try { Thread.sleep(45); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } // JOptionPane.showMessageDialog(null, tt); // viewport.setViewPosition(cellRect.getLocation()); }
package com.l2fprod.common.swing.table;
private int getResizingRow(Point p) { return getResizingRow(p, table.rowAtPoint(p)); }