List of usage examples for javax.swing JTable getCellRect
public Rectangle getCellRect(int row, int column, boolean includeSpacing)
row
and column
. From source file:Main.java
public static void scroll(JTable table, int row) { table.scrollRectToVisible(new Rectangle(table.getCellRect(row, 0, true))); }
From source file:Main.java
public static Rectangle getRowBounds(JTable table, int first, int last) { Rectangle result = table.getCellRect(first, -1, true); result = result.union(table.getCellRect(last, -1, true)); Insets i = table.getInsets(); result.x = i.left;//from www. ja v a2s.c o m result.width = table.getWidth() - i.left - i.right; return result; }
From source file:Main.java
public static void scrollToVisible(JTable table, int rowIndex, int vColIndex) { if (!(table.getParent() instanceof JViewport)) { return;/*w w w . j a va 2s .co m*/ } JViewport viewport = (JViewport) table.getParent(); Rectangle rect = table.getCellRect(rowIndex, vColIndex, true); Point pt = viewport.getViewPosition(); rect.setLocation(rect.x - pt.x, rect.y - pt.y); viewport.scrollRectToVisible(rect); }
From source file:Main.java
public static void scrollToCenter(JTable table, int rowIndex, int vColIndex) { if (!(table.getParent() instanceof JViewport)) { return;/* ww w . ja v a2s. c o m*/ } JViewport viewport = (JViewport) table.getParent(); Rectangle rect = table.getCellRect(rowIndex, vColIndex, true); Rectangle viewRect = viewport.getViewRect(); rect.setLocation(rect.x - viewRect.x, rect.y - viewRect.y); int centerX = (viewRect.width - rect.width) / 2; int centerY = (viewRect.height - rect.height) / 2; if (rect.x < centerX) { centerX = -centerX; } if (rect.y < centerY) { centerY = -centerY; } rect.translate(centerX, centerY); viewport.scrollRectToVisible(rect); }
From source file:Main.java
public static boolean isCellVisible(JTable table, int rowIndex, int vColIndex) { if (!(table.getParent() instanceof JViewport)) { return false; }/*from w w w .ja va 2s .co m*/ JViewport viewport = (JViewport) table.getParent(); Rectangle rect = table.getCellRect(rowIndex, vColIndex, true); Point pt = viewport.getViewPosition(); rect.setLocation(rect.x - pt.x, rect.y - pt.y); return new Rectangle(viewport.getExtentSize()).contains(rect); }
From source file:JTableHelper.java
public static void scrollToCenter(JTable table, int rowIndex, int vColIndex) { if (!(table.getParent() instanceof JViewport)) { return;/* ww w . j av a 2 s. co m*/ } JViewport viewport = (JViewport) table.getParent(); Rectangle rect = table.getCellRect(rowIndex, vColIndex, true); Rectangle viewRect = viewport.getViewRect(); rect.setLocation(rect.x - viewRect.x, rect.y - viewRect.y); int centerX = (viewRect.width - rect.width) / 2; int centerY = (viewRect.height - rect.height) / 2; if (rect.x < centerX) { centerX = -centerX; } if (rect.y < centerY) { centerY = -centerY; } rect.translate(centerX, centerY); viewport.scrollRectToVisible(rect); }
From source file:com.SCI.centraltoko.utility.UtilityTools.java
public static void scroolTorect(JTable tabel, int nextRow) { Rectangle currenVisible = tabel.getVisibleRect(); Rectangle scroolTorect = tabel.getCellRect(nextRow, 0, true); if (scroolTorect.getY() > currenVisible.getY() + currenVisible.getHeight()) { scroolTorect.setLocation(0,//w w w . j a v a 2s .c o m (int) (scroolTorect.getY() + currenVisible.getHeight() - scroolTorect.getHeight())); } tabel.scrollRectToVisible(scroolTorect); }
From source file:Main.java
/** * Scrolls a table so that a certain cell becomes visible. * Source: http://javaalmanac.com/egs/javax.swing.table/Vis.html * @param table//from ww w .j ava2s. co m * @param rowIndex * @param vColIndex */ public static void scrollToVisible(JTable table, int rowIndex, int vColIndex) { if (!(table.getParent() instanceof JViewport)) { return; } JViewport viewport = (JViewport) table.getParent(); // This rectangle is relative to the table where the // northwest corner of cell (0,0) is always (0,0). Rectangle rect = table.getCellRect(rowIndex, vColIndex, true); // The location of the viewport relative to the table Point pt = viewport.getViewPosition(); // Translate the cell location so that it is relative // to the view, assuming the northwest corner of the // view is (0,0) rect.setLocation(rect.x - pt.x, rect.y - pt.y); table.scrollRectToVisible(rect); // Scroll the area into view //viewport.scrollRectToVisible(rect); }
From source file:Main.java
/** * Assumes table is contained in a JScrollPane. * Scrolls the cell (rowIndex, vColIndex) so that it is visible * within the viewport./*from w w w . j a v a2s .c o m*/ */ public static void scrollToVisible(JTable table, int row, int col) { if (!(table.getParent() instanceof JViewport)) return; JViewport viewport = (JViewport) table.getParent(); // This rectangle is relative to the table where the // northwest corner of cell (0,0) is always (0,0). Rectangle rect = table.getCellRect(row, col, true); // The location of the viewport relative to the table Point pt = viewport.getViewPosition(); // Translate the cell location so that it is relative // to the view, assuming the northwest corner of the // view is (0,0) rect.setLocation(rect.x - pt.x, rect.y - pt.y); // Scroll the area into view viewport.scrollRectToVisible(rect); }
From source file:Main.java
/** * * @param table/*from w w w . ja v a 2 s . c o m*/ * @param row * @param column * @param p * @return */ public static boolean pointOutsidePrefSize(JTable table, int row, int column, Point p) { if ((table.convertColumnIndexToModel(column) != 0) || (row == -1)) { return true; } TableCellRenderer tcr = table.getCellRenderer(row, column); Object value = table.getValueAt(row, column); Component cell = tcr.getTableCellRendererComponent(table, value, false, false, row, column); Dimension itemSize = cell.getPreferredSize(); Rectangle cellBounds = table.getCellRect(row, column, false); cellBounds.width = itemSize.width; cellBounds.height = itemSize.height; // See if coords are inside // ASSUME: mouse x,y will never be < cell's x,y assert ((p.x >= cellBounds.x) && (p.y >= cellBounds.y)); if ((p.x > (cellBounds.x + cellBounds.width)) || (p.y > (cellBounds.y + cellBounds.height))) { return true; } return false; }