Java Code Examples for javax.swing.JViewport#getViewSize()
The following examples show how to use
javax.swing.JViewport#getViewSize() .
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: Test6526631.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public void validateThird() { JViewport viewport = this.pane.getViewport(); JScrollBar scroller = this.pane.getHorizontalScrollBar(); if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) { throw new Error("unexpected component orientation"); } int value = scroller.getValue(); if (value != 0) { throw new Error("unexpected scroll value"); } int extent = viewport.getExtentSize().width; if (extent != scroller.getVisibleAmount()) { throw new Error("unexpected visible amount"); } int size = viewport.getViewSize().width; if (size != scroller.getMaximum()) { throw new Error("unexpected maximum"); } int pos = size - extent - value; if (pos != viewport.getViewPosition().x) { throw new Error("unexpected position"); } }
Example 2
Source File: Test6526631.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public void validateThird() { JViewport viewport = this.pane.getViewport(); JScrollBar scroller = this.pane.getHorizontalScrollBar(); if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) { throw new Error("unexpected component orientation"); } int value = scroller.getValue(); if (value != 0) { throw new Error("unexpected scroll value"); } int extent = viewport.getExtentSize().width; if (extent != scroller.getVisibleAmount()) { throw new Error("unexpected visible amount"); } int size = viewport.getViewSize().width; if (size != scroller.getMaximum()) { throw new Error("unexpected maximum"); } int pos = size - extent - value; if (pos != viewport.getViewPosition().x) { throw new Error("unexpected position"); } }
Example 3
Source File: CloseTabPaneUI.java From iBioSim with Apache License 2.0 | 6 votes |
@Override public void stateChanged(ChangeEvent e) { JViewport viewport = (JViewport) e.getSource(); int tabPlacement = tabPane.getTabPlacement(); int tabCount = tabPane.getTabCount(); Rectangle vpRect = viewport.getBounds(); Dimension viewSize = viewport.getViewSize(); Rectangle viewRect = viewport.getViewRect(); leadingTabIndex = getClosestTab(viewRect.x, viewRect.y); // If the tab isn't right aligned, adjust it. if (leadingTabIndex + 1 < tabCount) { if (rects[leadingTabIndex].x < viewRect.x) { leadingTabIndex++; } } Insets contentInsets = getContentBorderInsets(tabPlacement); tabPane.repaint(vpRect.x, vpRect.y + vpRect.height, vpRect.width, contentInsets.top); scrollBackwardButton.setEnabled(viewRect.x > 0); scrollForwardButton.setEnabled(leadingTabIndex < tabCount - 1 && viewSize.width - viewRect.x > viewRect.width); }
Example 4
Source File: Test6526631.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public void validateThird() { JViewport viewport = this.pane.getViewport(); JScrollBar scroller = this.pane.getHorizontalScrollBar(); if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) { throw new Error("unexpected component orientation"); } int value = scroller.getValue(); if (value != 0) { throw new Error("unexpected scroll value"); } int extent = viewport.getExtentSize().width; if (extent != scroller.getVisibleAmount()) { throw new Error("unexpected visible amount"); } int size = viewport.getViewSize().width; if (size != scroller.getMaximum()) { throw new Error("unexpected maximum"); } int pos = size - extent - value; if (pos != viewport.getViewPosition().x) { throw new Error("unexpected position"); } }
Example 5
Source File: Test6526631.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public void validateThird() { JViewport viewport = this.pane.getViewport(); JScrollBar scroller = this.pane.getHorizontalScrollBar(); if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) { throw new Error("unexpected component orientation"); } int value = scroller.getValue(); if (value != 0) { throw new Error("unexpected scroll value"); } int extent = viewport.getExtentSize().width; if (extent != scroller.getVisibleAmount()) { throw new Error("unexpected visible amount"); } int size = viewport.getViewSize().width; if (size != scroller.getMaximum()) { throw new Error("unexpected maximum"); } int pos = size - extent - value; if (pos != viewport.getViewPosition().x) { throw new Error("unexpected position"); } }
Example 6
Source File: Test6526631.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public void validateThird() { JViewport viewport = this.pane.getViewport(); JScrollBar scroller = this.pane.getHorizontalScrollBar(); if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) { throw new Error("unexpected component orientation"); } int value = scroller.getValue(); if (value != 0) { throw new Error("unexpected scroll value"); } int extent = viewport.getExtentSize().width; if (extent != scroller.getVisibleAmount()) { throw new Error("unexpected visible amount"); } int size = viewport.getViewSize().width; if (size != scroller.getMaximum()) { throw new Error("unexpected maximum"); } int pos = size - extent - value; if (pos != viewport.getViewPosition().x) { throw new Error("unexpected position"); } }
Example 7
Source File: Test6526631.java From hottub with GNU General Public License v2.0 | 6 votes |
public void validateThird() { JViewport viewport = this.pane.getViewport(); JScrollBar scroller = this.pane.getHorizontalScrollBar(); if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) { throw new Error("unexpected component orientation"); } int value = scroller.getValue(); if (value != 0) { throw new Error("unexpected scroll value"); } int extent = viewport.getExtentSize().width; if (extent != scroller.getVisibleAmount()) { throw new Error("unexpected visible amount"); } int size = viewport.getViewSize().width; if (size != scroller.getMaximum()) { throw new Error("unexpected maximum"); } int pos = size - extent - value; if (pos != viewport.getViewPosition().x) { throw new Error("unexpected position"); } }
Example 8
Source File: Test6526631.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public void validateThird() { JViewport viewport = this.pane.getViewport(); JScrollBar scroller = this.pane.getHorizontalScrollBar(); if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) { throw new Error("unexpected component orientation"); } int value = scroller.getValue(); if (value != 0) { throw new Error("unexpected scroll value"); } int extent = viewport.getExtentSize().width; if (extent != scroller.getVisibleAmount()) { throw new Error("unexpected visible amount"); } int size = viewport.getViewSize().width; if (size != scroller.getMaximum()) { throw new Error("unexpected maximum"); } int pos = size - extent - value; if (pos != viewport.getViewPosition().x) { throw new Error("unexpected position"); } }
Example 9
Source File: Test6526631.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public void validateThird() { JViewport viewport = this.pane.getViewport(); JScrollBar scroller = this.pane.getHorizontalScrollBar(); if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) { throw new Error("unexpected component orientation"); } int value = scroller.getValue(); if (value != 0) { throw new Error("unexpected scroll value"); } int extent = viewport.getExtentSize().width; if (extent != scroller.getVisibleAmount()) { throw new Error("unexpected visible amount"); } int size = viewport.getViewSize().width; if (size != scroller.getMaximum()) { throw new Error("unexpected maximum"); } int pos = size - extent - value; if (pos != viewport.getViewPosition().x) { throw new Error("unexpected position"); } }
Example 10
Source File: Test6526631.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public void validateThird() { JViewport viewport = this.pane.getViewport(); JScrollBar scroller = this.pane.getHorizontalScrollBar(); if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) { throw new Error("unexpected component orientation"); } int value = scroller.getValue(); if (value != 0) { throw new Error("unexpected scroll value"); } int extent = viewport.getExtentSize().width; if (extent != scroller.getVisibleAmount()) { throw new Error("unexpected visible amount"); } int size = viewport.getViewSize().width; if (size != scroller.getMaximum()) { throw new Error("unexpected maximum"); } int pos = size - extent - value; if (pos != viewport.getViewPosition().x) { throw new Error("unexpected position"); } }
Example 11
Source File: GtpShell.java From FancyBing with GNU General Public License v3.0 | 6 votes |
private void scrollPage(boolean up) { JViewport viewport = m_scrollPane.getViewport(); Point position = viewport.getViewPosition(); int delta = m_scrollPane.getSize().height - m_gtpShellText.getFont().getSize(); if (up) { position.y -= delta; if (position.y < 0) position.y = 0; } else { position.y += delta; int max = viewport.getViewSize().height - m_scrollPane.getSize().height; if (position.y > max) position.y = max; } viewport.setViewPosition(position); }
Example 12
Source File: Test6526631.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public void validateThird() { JViewport viewport = this.pane.getViewport(); JScrollBar scroller = this.pane.getHorizontalScrollBar(); if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) { throw new Error("unexpected component orientation"); } int value = scroller.getValue(); if (value != 0) { throw new Error("unexpected scroll value"); } int extent = viewport.getExtentSize().width; if (extent != scroller.getVisibleAmount()) { throw new Error("unexpected visible amount"); } int size = viewport.getViewSize().width; if (size != scroller.getMaximum()) { throw new Error("unexpected maximum"); } int pos = size - extent - value; if (pos != viewport.getViewPosition().x) { throw new Error("unexpected position"); } }
Example 13
Source File: Test6526631.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public void validateThird() { JViewport viewport = this.pane.getViewport(); JScrollBar scroller = this.pane.getHorizontalScrollBar(); if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) { throw new Error("unexpected component orientation"); } int value = scroller.getValue(); if (value != 0) { throw new Error("unexpected scroll value"); } int extent = viewport.getExtentSize().width; if (extent != scroller.getVisibleAmount()) { throw new Error("unexpected visible amount"); } int size = viewport.getViewSize().width; if (size != scroller.getMaximum()) { throw new Error("unexpected maximum"); } int pos = size - extent - value; if (pos != viewport.getViewPosition().x) { throw new Error("unexpected position"); } }
Example 14
Source File: Test6526631.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public void validateThird() { JViewport viewport = this.pane.getViewport(); JScrollBar scroller = this.pane.getHorizontalScrollBar(); if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) { throw new Error("unexpected component orientation"); } int value = scroller.getValue(); if (value != 0) { throw new Error("unexpected scroll value"); } int extent = viewport.getExtentSize().width; if (extent != scroller.getVisibleAmount()) { throw new Error("unexpected visible amount"); } int size = viewport.getViewSize().width; if (size != scroller.getMaximum()) { throw new Error("unexpected maximum"); } int pos = size - extent - value; if (pos != viewport.getViewPosition().x) { throw new Error("unexpected position"); } }
Example 15
Source File: DebuggingViewComponent.java From netbeans with Apache License 2.0 | 5 votes |
private void adjustTreeScrollBar(int treeViewWidth) { DebugTreeView tView = getTreeView(); if (tView == null) { scrollBarPanel.setVisible(false); return; } JViewport viewport = tView.getViewport(); Point point = viewport.getViewPosition(); if (point.y < 0) { viewport.setViewPosition(new Point(point.x, 0)); } Dimension viewSize = viewport.getExtentSize(); Dimension treeSize = viewport.getViewSize(); if (treeViewWidth < 0) { treeViewWidth = treeSize.width; } int unitHeight = tView.getUnitHeight(); if (unitHeight > 0) { JScrollBar sbar = mainScrollPane.getVerticalScrollBar(); if (sbar.getUnitIncrement() != unitHeight) { sbar.setUnitIncrement(unitHeight); } } if (treeViewWidth <= viewSize.width) { scrollBarPanel.setVisible(false); } else { treeScrollBar.setMaximum(treeViewWidth); treeScrollBar.setVisibleAmount(viewSize.width); if (unitHeight > 0) { treeScrollBar.setUnitIncrement(unitHeight / 2); } treeScrollBar.setBlockIncrement(viewSize.width); scrollBarPanel.setVisible(true); } // else }
Example 16
Source File: SeaGlassScrollPaneUI.java From seaglass with Apache License 2.0 | 5 votes |
private void sbPropertyChange(PropertyChangeEvent e) { String propertyName = e.getPropertyName(); Object source = e.getSource(); if ("model" == propertyName) { JScrollBar sb = scrollpane.getVerticalScrollBar(); BoundedRangeModel oldModel = (BoundedRangeModel) e.getOldValue(); ChangeListener cl = null; if (source == sb) { cl = vsbChangeListener; } else if (source == scrollpane.getHorizontalScrollBar()) { sb = scrollpane.getHorizontalScrollBar(); cl = hsbChangeListener; } if (cl != null) { if (oldModel != null) { oldModel.removeChangeListener(cl); } if (sb.getModel() != null) { sb.getModel().addChangeListener(cl); } } } else if ("componentOrientation" == propertyName) { if (source == scrollpane.getHorizontalScrollBar()) { JScrollBar hsb = scrollpane.getHorizontalScrollBar(); JViewport viewport = scrollpane.getViewport(); Point p = viewport.getViewPosition(); if (scrollpane.getComponentOrientation().isLeftToRight()) { p.x = hsb.getValue(); } else { p.x = viewport.getViewSize().width - viewport.getExtentSize().width - hsb.getValue(); } viewport.setViewPosition(p); } } }
Example 17
Source File: SmoothScrollPaneUI.java From netbeans with Apache License 2.0 | 5 votes |
private void mouseWheelMoved(MouseWheelEvent e) { /* The code in this method is taken directly from Pavel Fatin's original IntelliJ patch. Some formatting changes have been applied. */ /* The shift modifier will be enabled for horizontal touchbar scroll events, even when the actual shift key is not pressed, on both Windows and MacOS (though not on Java 8 on Windows). */ JScrollBar scrollbar = e.isShiftDown() ? scrollpane.getHorizontalScrollBar() : scrollpane.getVerticalScrollBar(); int orientation = scrollbar.getOrientation(); JViewport viewport = scrollpane.getViewport(); if (viewport == null || !(viewport.getView() instanceof Scrollable)) { return; } Scrollable view = (Scrollable) viewport.getView(); double rotation = e.getPreciseWheelRotation(); /* Use (0, 0) view position to obtain constant unit increment (which might otherwise be variable on smaller-than-unit scrolling). */ Rectangle r = new Rectangle(new Point(0, 0), viewport.getViewSize()); int unitIncrement = view.getScrollableUnitIncrement(r, orientation, 1); double delta = rotation * e.getScrollAmount() * unitIncrement; boolean limitDelta = Math.abs(rotation) < 1.0d + EPSILON; int blockIncrement = view.getScrollableBlockIncrement(r, orientation, 1); double adjustedDelta = limitDelta ? Math.max(-(double) blockIncrement, Math.min(delta, (double) blockIncrement)) : delta; int value = scrollbar.getValue(); int newValue = Math.max(scrollbar.getMinimum(), Math.min((int) Math.round(value + adjustedDelta), scrollbar.getMaximum())); if (newValue != value) { scrollbar.setValue(newValue); } }
Example 18
Source File: CustomScroll.java From mars-sim with GNU General Public License v3.0 | 5 votes |
private void displayVerticalScrollBarIfNecessary(JViewport viewPort) { Rectangle viewRect = viewPort.getViewRect(); Dimension viewSize = viewPort.getViewSize(); boolean shouldDisplayVerticalScrollBar = viewSize.getHeight() > viewRect.getHeight(); verticalScrollBar.setVisible(shouldDisplayVerticalScrollBar); }
Example 19
Source File: SeaGlassScrollPaneUI.java From seaglass with Apache License 2.0 | 5 votes |
private void hsbStateChanged(JViewport viewport, ChangeEvent e) { BoundedRangeModel model = (BoundedRangeModel) (e.getSource()); Point p = viewport.getViewPosition(); int value = model.getValue(); if (scrollpane.getComponentOrientation().isLeftToRight()) { p.x = value; } else { int max = viewport.getViewSize().width; int extent = viewport.getExtentSize().width; int oldX = p.x; /* * Set new X coordinate based on "value". */ p.x = max - extent - value; /* * If setValue() was called before "extent" was fixed, turn * setValueCalled flag on. */ if ((extent == 0) && (value != 0) && (oldX == max)) { setValueCalled = true; } else { /* * When a pane without a horizontal scroll bar was reduced * and the bar appeared, the viewport should show the right * side of the view. */ if ((extent != 0) && (oldX < 0) && (p.x == 0)) { p.x += value; } } } viewport.setViewPosition(p); }
Example 20
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 ) ); */ }