Java Code Examples for javax.swing.JViewport#getHeight()
The following examples show how to use
javax.swing.JViewport#getHeight() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditorUI.java From netbeans with Apache License 2.0 | 6 votes |
/** Get position of the component extent. The (x, y) are set to (0, 0) if there's * no viewport or (-x, -y) if there's one. */ public Rectangle getExtentBounds(Rectangle r) { if (r == null) { r = new Rectangle(); } if (component != null) { JViewport port = getParentViewport(); if (port != null) { Point p = port.getViewPosition(); r.width = port.getWidth(); r.height = port.getHeight(); r.x = p.x; r.y = p.y; } else { // no viewport r.setBounds(component.getVisibleRect()); } } return r; }
Example 2
Source File: GraphPanel.java From chipster with MIT License | 6 votes |
/** * Zooms out. */ private void zoomOutToolUsed() { if (this.setGraphScale(graph.getScale() / this.ZOOM_FACTOR)) { JViewport view = this.getScroller().getViewport(); Point viewPos = view.getViewPosition(); center = new Point((int) (viewPos.getX() + view.getWidth() / 2), (int) (viewPos.getY() + view.getHeight() / 2)); center.x = (int) (center.getX() / this.ZOOM_FACTOR); center.y = (int) (center.getY() / this.ZOOM_FACTOR); updateGridSize(); this.pointToCenter(center); } this.repaint(); this.getScroller().repaint(); graph.repaint(); }
Example 3
Source File: MasterCli.java From brModelo with GNU General Public License v3.0 | 5 votes |
public void AtualizaTamanho() { int pos = alturaTexto; if (pos > getHeight()) { JViewport jvp = ((JViewport) getParent()); setSize(jvp.getExtentSize().width, pos + 2); setPreferredSize(getSize()); if (alturaTexto > jvp.getHeight()) { jvp.setViewPosition(new Point(espaco, getHeight())); } repaint(); } }
Example 4
Source File: JRViewerPanel.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
void pnlLinksMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlLinksMouseDragged // Add your handling code here: Container container = pnlInScroll.getParent(); if (container instanceof JViewport) { JViewport viewport = (JViewport) container; Point point = viewport.getViewPosition(); int newX = point.x - (evt.getX() - downX); int newY = point.y - (evt.getY() - downY); int maxX = pnlInScroll.getWidth() - viewport.getWidth(); int maxY = pnlInScroll.getHeight() - viewport.getHeight(); if (newX < 0) { newX = 0; } if (newX > maxX) { newX = maxX; } if (newY < 0) { newY = 0; } if (newY > maxY) { newY = maxY; } viewport.setViewPosition(new Point(newX, newY)); } }
Example 5
Source File: JRViewer.java From nordpos with GNU General Public License v3.0 | 5 votes |
void pnlLinksMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlLinksMouseDragged // Add your handling code here: Container container = pnlInScroll.getParent(); if (container instanceof JViewport) { JViewport viewport = (JViewport) container; Point point = viewport.getViewPosition(); int newX = point.x - (evt.getX() - downX); int newY = point.y - (evt.getY() - downY); int maxX = pnlInScroll.getWidth() - viewport.getWidth(); int maxY = pnlInScroll.getHeight() - viewport.getHeight(); if (newX < 0) { newX = 0; } if (newX > maxX) { newX = maxX; } if (newY < 0) { newY = 0; } if (newY > maxY) { newY = maxY; } viewport.setViewPosition(new Point(newX, newY)); } }
Example 6
Source File: FlatScrollPaneUI.java From FlatLaf with Apache License 2.0 | 4 votes |
private void mouseWheelMovedSmooth( MouseWheelEvent e ) { // return if there is no viewport JViewport viewport = scrollpane.getViewport(); if( viewport == null ) return; // find scrollbar to scroll JScrollBar scrollbar = scrollpane.getVerticalScrollBar(); if( scrollbar == null || !scrollbar.isVisible() || e.isShiftDown() ) { scrollbar = scrollpane.getHorizontalScrollBar(); if( scrollbar == null || !scrollbar.isVisible() ) return; } // consume event e.consume(); // get precise wheel rotation double rotation = e.getPreciseWheelRotation(); // get unit and block increment int unitIncrement; int blockIncrement; int orientation = scrollbar.getOrientation(); Component view = viewport.getView(); if( view instanceof Scrollable ) { Scrollable scrollable = (Scrollable) view; // Use (0, 0) view position to obtain constant unit increment of first item // (which might otherwise be variable on smaller-than-unit scrolling). Rectangle visibleRect = new Rectangle( viewport.getViewSize() ); unitIncrement = scrollable.getScrollableUnitIncrement( visibleRect, orientation, 1 ); blockIncrement = scrollable.getScrollableBlockIncrement( visibleRect, orientation, 1 ); if( unitIncrement > 0 ) { // For the case that the first item (e.g. in a list) is larger // than the other items, get the unit increment of the second item // and use the smaller one. if( orientation == SwingConstants.VERTICAL ) { visibleRect.y += unitIncrement; visibleRect.height -= unitIncrement; } else { visibleRect.x += unitIncrement; visibleRect.width -= unitIncrement; } int unitIncrement2 = scrollable.getScrollableUnitIncrement( visibleRect, orientation, 1 ); if( unitIncrement2 > 0 ) unitIncrement = Math.min( unitIncrement, unitIncrement2 ); } } else { int direction = rotation < 0 ? -1 : 1; unitIncrement = scrollbar.getUnitIncrement( direction ); blockIncrement = scrollbar.getBlockIncrement( direction ); } // limit scroll amount (number of units to scroll) for small viewports // (e.g. vertical scrolling in file chooser) int scrollAmount = e.getScrollAmount(); int viewportWH = (orientation == SwingConstants.VERTICAL) ? viewport.getHeight() : viewport.getWidth(); if( unitIncrement * scrollAmount > viewportWH ) scrollAmount = Math.max( viewportWH / unitIncrement, 1 ); // compute relative delta double delta = rotation * scrollAmount * unitIncrement; boolean adjustDelta = Math.abs( rotation ) < (1.0 + EPSILON); double adjustedDelta = adjustDelta ? Math.max( -blockIncrement, Math.min( delta, blockIncrement ) ) : delta; // compute new value int value = scrollbar.getValue(); double minDelta = scrollbar.getMinimum() - value; double maxDelta = scrollbar.getMaximum() - scrollbar.getModel().getExtent() - value; double boundedDelta = Math.max( minDelta, Math.min( adjustedDelta, maxDelta ) ); int newValue = value + (int) Math.round( boundedDelta ); // set new value if( newValue != value ) scrollbar.setValue( newValue ); /*debug System.out.println( String.format( "%4d %9f / %4d %4d / %12f %5s %12f / %4d %4d %4d / %12f %12f %12f / %4d", e.getWheelRotation(), e.getPreciseWheelRotation(), unitIncrement, blockIncrement, delta, adjustDelta, adjustedDelta, value, scrollbar.getMinimum(), scrollbar.getMaximum(), minDelta, maxDelta, boundedDelta, newValue ) ); */ }
Example 7
Source File: ExtendedJTableColumnFitMouseListener.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
@Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { JTableHeader header = (JTableHeader) e.getSource(); TableColumn tableColumn = getResizingColumn(header, e.getPoint()); if (tableColumn == null) { return; } JTable table = header.getTable(); if ((e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK) { if (table instanceof ExtendedJTable) { ((ExtendedJTable) table).pack(); e.consume(); } } else { int col = header.getColumnModel().getColumnIndex(tableColumn.getIdentifier()); int width = (int) header.getDefaultRenderer() .getTableCellRendererComponent(table, tableColumn.getIdentifier(), false, false, -1, col) .getPreferredSize().getWidth(); int firstRow = 0; int lastRow = table.getRowCount(); if (table instanceof ExtendedJTable) { ExtendedJScrollPane scrollPane = ((ExtendedJTable) table).getExtendedScrollPane(); if (scrollPane != null) { JViewport viewport = scrollPane.getViewport(); Rectangle viewRect = viewport.getViewRect(); if (viewport.getHeight() < table.getHeight()) { firstRow = table.rowAtPoint(new Point(0, viewRect.y)); firstRow = Math.max(0, firstRow); lastRow = table.rowAtPoint(new Point(0, viewRect.y + viewRect.height - 1)); lastRow = Math.min(lastRow, table.getRowCount()); } } } for (int row = firstRow; row < lastRow; 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); } header.setResizingColumn(tableColumn); // this line is very important tableColumn.setWidth(width + table.getIntercellSpacing().width); e.consume(); } } }
Example 8
Source File: ExtendedJTable.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
public void packColumn() { JTableHeader header = getTableHeader(); if (header != null) { int col = getSelectedColumn(); if (col >= 0) { TableColumn tableColumn = header.getColumnModel().getColumn(col); if (tableColumn != null) { int width = (int) header.getDefaultRenderer() .getTableCellRendererComponent(this, tableColumn.getIdentifier(), false, false, -1, col) .getPreferredSize().getWidth(); int firstRow = 0; int lastRow = getRowCount(); ExtendedJScrollPane scrollPane = getExtendedScrollPane(); if (scrollPane != null) { JViewport viewport = scrollPane.getViewport(); Rectangle viewRect = viewport.getViewRect(); if (viewport.getHeight() < getHeight()) { firstRow = rowAtPoint(new Point(0, viewRect.y)); firstRow = Math.max(0, firstRow); lastRow = rowAtPoint(new Point(0, viewRect.y + viewRect.height - 1)); lastRow = Math.min(lastRow, getRowCount()); } } for (int row = firstRow; row < lastRow; row++) { int preferedWidth = (int) getCellRenderer(row, col) .getTableCellRendererComponent(this, getValueAt(row, col), false, false, row, col) .getPreferredSize().getWidth(); width = Math.max(width, preferedWidth); } header.setResizingColumn(tableColumn); // this line is very important tableColumn.setWidth(width + getIntercellSpacing().width); } } } }
Example 9
Source File: GraphPanel.java From chipster with MIT License | 4 votes |
/** * Zoom in * * @param e */ private void zoomInToolUsed() { // If the zoom-limit has been reached, don't do anything if (this.setGraphScale(graph.getScale() * this.ZOOM_FACTOR)) { JViewport view = this.getScroller().getViewport(); Point viewPos = view.getViewPosition(); center = new Point((int) (viewPos.getX() + view.getWidth() / 2), (int) (viewPos.getY() + view.getHeight() / 2)); logger.debug("view.getX: " + view.getX() + ", viewWidth: " + view.getWidth()); // Make the coordinates to correspond the new size of the graph center.x = (int) (center.getX() * this.ZOOM_FACTOR); center.y = (int) (center.getY() * this.ZOOM_FACTOR); /* * The new scale won't be applied before this method is ended. The new scale changes the size of the graph, which affects on the * calculations done in method pointToCenter. We couuld estimate the new size of the graph, but that doesn't help because we * still cant scroll to the new areas. */ Runnable centerer = new Thread() { public void run() { try { Thread.sleep(10); } catch (InterruptedException e) { // Nothing serious happened } GraphPanel.this.pointToCenter(GraphPanel.this.center); } }; updateGridSize(); // try it to avoid flickering when possible this.pointToCenter(GraphPanel.this.center); // and make sure it's done in every situation; SwingUtilities.invokeLater(centerer); } graph.repaint(); }