List of usage examples for java.awt Rectangle setLocation
public void setLocation(int x, int y)
From source file:Main.java
public static void scrollToVisible(JTable table, int rowIndex, int vColIndex) { if (!(table.getParent() instanceof JViewport)) { return;/*from w w w.j a v a 2 s . com*/ } 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;//w w w. j a v a 2s . 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 ww .j ava 2 s . com*/ 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 2s. 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
/** * Scrolls a table so that a certain cell becomes visible. * Source: http://javaalmanac.com/egs/javax.swing.table/Vis.html * @param table//from w w w .ja v a 2s . 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 . ja v a2 s .co 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: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, (int) (scroolTorect.getY() + currenVisible.getHeight() - scroolTorect.getHeight())); }/*from w ww . ja v a2 s . c o m*/ tabel.scrollRectToVisible(scroolTorect); }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Rectangle r = new Rectangle(); r.setLocation(10, 10); r.setSize(10, 10);// w w w . j ava2 s . c o m g2.fill(r); System.out.println(r.height); }
From source file:com.igormaznitsa.sciareto.ui.editors.MMDEditor.java
@Override public void onEnsureVisibilityOfTopic(@Nonnull final MindMapPanel source, @Nullable final Topic topic) { SwingUtilities.invokeLater(new Runnable() { @Override/*w w w.j a v a2 s . c o m*/ public void run() { if (topic == null) { return; } final AbstractElement element = (AbstractElement) topic.getPayload(); if (element == null) { return; } final Rectangle2D orig = element.getBounds(); final int GAP = 30; final Rectangle bounds = orig.getBounds(); bounds.setLocation(Math.max(0, bounds.x - GAP), Math.max(0, bounds.y - GAP)); bounds.setSize(bounds.width + GAP * 2, bounds.height + GAP * 2); final JViewport viewport = getViewport(); final Rectangle visible = viewport.getViewRect(); if (visible.contains(bounds)) { return; } bounds.setLocation(bounds.x - visible.x, bounds.y - visible.y); viewport.scrollRectToVisible(bounds); } }); }
From source file:net.sf.jabref.gui.maintable.MainTable.java
public void scrollToCenter(int rowIndex, int vColIndex) { if (!(this.getParent() instanceof JViewport)) { return;/*from w ww . ja v a2 s . c o m*/ } JViewport viewport = (JViewport) this.getParent(); // This rectangle is relative to the table where the // northwest corner of cell (0,0) is always (0,0). Rectangle rect = this.getCellRect(rowIndex, vColIndex, true); // The location of the view relative to the table Rectangle viewRect = viewport.getViewRect(); // 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 - viewRect.x, rect.y - viewRect.y); // Calculate location of rect if it were at the center of view int centerX = (viewRect.width - rect.width) / 2; int centerY = (viewRect.height - rect.height) / 2; // Fake the location of the cell so that scrollRectToVisible // will move the cell to the center if (rect.x < centerX) { centerX = -centerX; } if (rect.y < centerY) { centerY = -centerY; } rect.translate(centerX, centerY); // Scroll the area into view. viewport.scrollRectToVisible(rect); revalidate(); repaint(); }