javax.swing.JScrollBar Java Examples
The following examples show how to use
javax.swing.JScrollBar.
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: LWTextAreaPeer.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public Dimension getMinimumSize(final int rows, final int columns) { final Dimension size = super.getMinimumSize(rows, columns); synchronized (getDelegateLock()) { // JScrollPane insets final Insets pi = getDelegate().getInsets(); size.width += pi.left + pi.right; size.height += pi.top + pi.bottom; // Take scrollbars into account. final int vsbPolicy = getDelegate().getVerticalScrollBarPolicy(); if (vsbPolicy == ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) { final JScrollBar vbar = getDelegate().getVerticalScrollBar(); size.width += vbar != null ? vbar.getMinimumSize().width : 0; } final int hsbPolicy = getDelegate().getHorizontalScrollBarPolicy(); if (hsbPolicy == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) { final JScrollBar hbar = getDelegate().getHorizontalScrollBar(); size.height += hbar != null ? hbar.getMinimumSize().height : 0; } } return size; }
Example #2
Source File: XTextAreaPeer.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override protected void uninstallDefaults(JScrollPane c) { super.uninstallDefaults(c); JScrollBar vsb = scrollpane.getVerticalScrollBar(); if (vsb != null) { if (vsb.getBorder() == vsbBorder) { vsb.setBorder(null); } vsbBorder = null; } JScrollBar hsb = scrollpane.getHorizontalScrollBar(); if (hsb != null) { if (hsb.getBorder() == hsbBorder) { hsb.setBorder(null); } hsbBorder = null; } }
Example #3
Source File: JScrollPopupMenu.java From zap-extensions with Apache License 2.0 | 6 votes |
public JScrollPopupMenu(String label) { super(label); setLayout(new ScrollPopupMenuLayout()); super.add(getScrollBar()); addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent event) { JScrollBar scrollBar = getScrollBar(); int amount = (event.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) ? event.getUnitsToScroll() * scrollBar.getUnitIncrement() : (event.getWheelRotation() < 0 ? -1 : 1) * scrollBar.getBlockIncrement(); scrollBar.setValue(scrollBar.getValue() + amount); event.consume(); } }); }
Example #4
Source File: XTextAreaPeer.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private boolean setPointerIfPointOverScrollbar( JScrollBar bar, Point point ) { if ( ! bar.getBounds().contains( point ) ) { return false; } current.setBar( bar ); Point local = toLocalSpace( bar, point ); XTextAreaPeer.XAWTScrollBarUI ui = (XTextAreaPeer.XAWTScrollBarUI) bar.getUI(); if ( ! setPointerIfPointOverButton( ui.getIncreaseButton(), local ) ) { setPointerIfPointOverButton( ui.getDecreaseButton(), local ); } return true; }
Example #5
Source File: LWTextAreaPeer.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public Dimension getMinimumSize(final int rows, final int columns) { final Dimension size = super.getMinimumSize(rows, columns); synchronized (getDelegateLock()) { // JScrollPane insets final Insets pi = getDelegate().getInsets(); size.width += pi.left + pi.right; size.height += pi.top + pi.bottom; // Take scrollbars into account. final int vsbPolicy = getDelegate().getVerticalScrollBarPolicy(); if (vsbPolicy == ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) { final JScrollBar vbar = getDelegate().getVerticalScrollBar(); size.width += vbar != null ? vbar.getMinimumSize().width : 0; } final int hsbPolicy = getDelegate().getHorizontalScrollBarPolicy(); if (hsbPolicy == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) { final JScrollBar hbar = getDelegate().getHorizontalScrollBar(); size.height += hbar != null ? hbar.getMinimumSize().height : 0; } } return size; }
Example #6
Source File: LWTextAreaPeer.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public void insert(final String text, final int pos) { final ScrollableJTextArea pane = getDelegate(); synchronized (getDelegateLock()) { final JTextArea area = pane.getView(); final boolean doScroll = pos >= area.getDocument().getLength() && area.getDocument().getLength() != 0; area.insert(text, pos); revalidate(); if (doScroll) { final JScrollBar vbar = pane.getVerticalScrollBar(); if (vbar != null) { vbar.setValue(vbar.getMaximum() - vbar.getVisibleAmount()); } } } repaintPeer(); }
Example #7
Source File: LWTextAreaPeer.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Override public Dimension getMinimumSize(final int rows, final int columns) { final Dimension size = super.getMinimumSize(rows, columns); synchronized (getDelegateLock()) { // JScrollPane insets final Insets pi = getDelegate().getInsets(); size.width += pi.left + pi.right; size.height += pi.top + pi.bottom; // Take scrollbars into account. final int vsbPolicy = getDelegate().getVerticalScrollBarPolicy(); if (vsbPolicy == ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) { final JScrollBar vbar = getDelegate().getVerticalScrollBar(); size.width += vbar != null ? vbar.getMinimumSize().width : 0; } final int hsbPolicy = getDelegate().getHorizontalScrollBarPolicy(); if (hsbPolicy == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) { final JScrollBar hbar = getDelegate().getHorizontalScrollBar(); size.height += hbar != null ? hbar.getMinimumSize().height : 0; } } return size; }
Example #8
Source File: XTextAreaPeer.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
private boolean setPointerIfPointOverScrollbar( JScrollBar bar, Point point ) { if ( ! bar.getBounds().contains( point ) ) { return false; } current.setBar( bar ); Point local = toLocalSpace( bar, point ); XTextAreaPeer.XAWTScrollBarUI ui = (XTextAreaPeer.XAWTScrollBarUI) bar.getUI(); if ( ! setPointerIfPointOverButton( ui.getIncreaseButton(), local ) ) { setPointerIfPointOverButton( ui.getDecreaseButton(), local ); } return true; }
Example #9
Source File: LWScrollBarPeer.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
@Override void initializeImpl() { super.initializeImpl(); final Scrollbar target = getTarget(); setLineIncrement(target.getUnitIncrement()); setPageIncrement(target.getBlockIncrement()); setValues(target.getValue(), target.getVisibleAmount(), target.getMinimum(), target.getMaximum()); final int orientation = target.getOrientation(); final JScrollBar delegate = getDelegate(); synchronized (getDelegateLock()) { delegate.setOrientation(orientation == Scrollbar.HORIZONTAL ? Adjustable.HORIZONTAL : Adjustable.VERTICAL); delegate.addAdjustmentListener(this); } }
Example #10
Source File: Test8039464.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static void init(Container container) { container.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.gridx = 0; gbc.gridy = 1; JLabel label = new JLabel(); Dimension size = new Dimension(111, 0); label.setPreferredSize(size); label.setMinimumSize(size); container.add(label, gbc); gbc.gridx = 1; gbc.weightx = 1; container.add(new JScrollBar(JScrollBar.HORIZONTAL, 1, 111, 1, 1111), gbc); gbc.gridx = 2; gbc.gridy = 0; gbc.weightx = 0; gbc.weighty = 1; container.add(new JScrollBar(JScrollBar.VERTICAL, 1, 111, 1, 1111), gbc); }
Example #11
Source File: SeaGlassScrollPaneUI.java From seaglass with Apache License 2.0 | 6 votes |
void scrollByBlock(JScrollBar scrollbar, int direction) { // This method is called from BasicScrollPaneUI to implement wheel // scrolling, and also from scrollByBlock(). int oldValue = scrollbar.getValue(); int blockIncrement = scrollbar.getBlockIncrement(direction); int delta = blockIncrement * ((direction > 0) ? +1 : -1); int newValue = oldValue + delta; // Check for overflow. if (delta > 0 && newValue < oldValue) { newValue = scrollbar.getMaximum(); } else if (delta < 0 && newValue > oldValue) { newValue = scrollbar.getMinimum(); } scrollbar.setValue(newValue); }
Example #12
Source File: Test7163696.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public void run() { if (this.bar == null) { this.bar = new JScrollBar(JScrollBar.HORIZONTAL, 50, 10, 0, 100); this.bar.setPreferredSize(new Dimension(400, 20)); JFrame frame = new JFrame(); frame.add(this.bar); frame.pack(); frame.setVisible(true); } else if (40 != this.bar.getValue()) { System.out.println("name = " + UIManager.getLookAndFeel().getName()); System.out.println("value = " + this.bar.getValue()); } else { SwingUtilities.getWindowAncestor(this.bar).dispose(); this.bar = null; } }
Example #13
Source File: XTextAreaPeer.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
@Override protected void uninstallDefaults(JScrollPane c) { super.uninstallDefaults(c); JScrollBar vsb = scrollpane.getVerticalScrollBar(); if (vsb != null) { if (vsb.getBorder() == vsbBorder) { vsb.setBorder(null); } vsbBorder = null; } JScrollBar hsb = scrollpane.getHorizontalScrollBar(); if (hsb != null) { if (hsb.getBorder() == hsbBorder) { hsb.setBorder(null); } hsbBorder = null; } }
Example #14
Source File: LWScrollBarPeer.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
@Override void initializeImpl() { super.initializeImpl(); final Scrollbar target = getTarget(); setLineIncrement(target.getUnitIncrement()); setPageIncrement(target.getBlockIncrement()); setValues(target.getValue(), target.getVisibleAmount(), target.getMinimum(), target.getMaximum()); final int orientation = target.getOrientation(); final JScrollBar delegate = getDelegate(); synchronized (getDelegateLock()) { delegate.setOrientation(orientation == Scrollbar.HORIZONTAL ? Adjustable.HORIZONTAL : Adjustable.VERTICAL); delegate.addAdjustmentListener(this); } }
Example #15
Source File: XTextAreaPeer.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private boolean setPointerIfPointOverScrollbar( JScrollBar bar, Point point ) { if ( ! bar.getBounds().contains( point ) ) { return false; } current.setBar( bar ); Point local = toLocalSpace( bar, point ); XTextAreaPeer.XAWTScrollBarUI ui = (XTextAreaPeer.XAWTScrollBarUI) bar.getUI(); if ( ! setPointerIfPointOverButton( ui.getIncreaseButton(), local ) ) { setPointerIfPointOverButton( ui.getDecreaseButton(), local ); } return true; }
Example #16
Source File: LWTextAreaPeer.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public void insert(final String text, final int pos) { final ScrollableJTextArea pane = getDelegate(); synchronized (getDelegateLock()) { final JTextArea area = pane.getView(); final boolean doScroll = pos >= area.getDocument().getLength() && area.getDocument().getLength() != 0; area.insert(text, pos); revalidate(); if (doScroll) { final JScrollBar vbar = pane.getVerticalScrollBar(); if (vbar != null) { vbar.setValue(vbar.getMaximum() - vbar.getVisibleAmount()); } } } repaintPeer(); }
Example #17
Source File: JScrollPaneOperator.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public int getScrollDirection(JScrollBarOperator oper) { Point toPoint = SwingUtilities. convertPoint(comp, x, y, getViewport().getView()); int to = (orientation == JScrollBar.HORIZONTAL) ? toPoint.x : toPoint.y; int ln = (orientation == JScrollBar.HORIZONTAL) ? width : height; int lv = (orientation == JScrollBar.HORIZONTAL) ? getViewport().getWidth() : getViewport().getHeight(); int vl = oper.getValue(); if (to < vl) { return ScrollAdjuster.DECREASE_SCROLL_DIRECTION; } else if ((to + ln - 1) > (vl + lv) && to > vl) { return ScrollAdjuster.INCREASE_SCROLL_DIRECTION; } else { return ScrollAdjuster.DO_NOT_TOUCH_SCROLL_DIRECTION; } }
Example #18
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 #19
Source File: XTextAreaPeer.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override protected void uninstallDefaults(JScrollPane c) { super.uninstallDefaults(c); JScrollBar vsb = scrollpane.getVerticalScrollBar(); if (vsb != null) { if (vsb.getBorder() == vsbBorder) { vsb.setBorder(null); } vsbBorder = null; } JScrollBar hsb = scrollpane.getHorizontalScrollBar(); if (hsb != null) { if (hsb.getBorder() == hsbBorder) { hsb.setBorder(null); } hsbBorder = null; } }
Example #20
Source File: LWTextAreaPeer.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Override public void insert(final String text, final int pos) { final ScrollableJTextArea pane = getDelegate(); synchronized (getDelegateLock()) { final JTextArea area = pane.getView(); final boolean doScroll = pos >= area.getDocument().getLength() && area.getDocument().getLength() != 0; area.insert(text, pos); revalidate(); if (doScroll) { final JScrollBar vbar = pane.getVerticalScrollBar(); if (vbar != null) { vbar.setValue(vbar.getMaximum() - vbar.getVisibleAmount()); } } } repaintPeer(); }
Example #21
Source File: XTextAreaPeer.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
private boolean setPointerIfPointOverScrollbar( JScrollBar bar, Point point ) { if ( ! bar.getBounds().contains( point ) ) { return false; } current.setBar( bar ); Point local = toLocalSpace( bar, point ); XTextAreaPeer.XAWTScrollBarUI ui = (XTextAreaPeer.XAWTScrollBarUI) bar.getUI(); if ( ! setPointerIfPointOverButton( ui.getIncreaseButton(), local ) ) { setPointerIfPointOverButton( ui.getDecreaseButton(), local ); } return true; }
Example #22
Source File: Test7163696.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public void run() { if (this.bar == null) { this.bar = new JScrollBar(JScrollBar.HORIZONTAL, 50, 10, 0, 100); this.bar.setPreferredSize(new Dimension(400, 20)); JFrame frame = new JFrame(); frame.add(this.bar); frame.pack(); frame.setVisible(true); } else if (40 != this.bar.getValue()) { System.out.println("name = " + UIManager.getLookAndFeel().getName()); System.out.println("value = " + this.bar.getValue()); } else { SwingUtilities.getWindowAncestor(this.bar).dispose(); this.bar = null; } }
Example #23
Source File: Test7163696.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public void run() { if (this.bar == null) { this.bar = new JScrollBar(JScrollBar.HORIZONTAL, 50, 10, 0, 100); this.bar.setPreferredSize(new Dimension(400, 20)); JFrame frame = new JFrame(); frame.add(this.bar); frame.pack(); frame.setVisible(true); } else if (40 != this.bar.getValue()) { System.out.println("name = " + UIManager.getLookAndFeel().getName()); System.out.println("value = " + this.bar.getValue()); } else { SwingUtilities.getWindowAncestor(this.bar).dispose(); this.bar = null; } }
Example #24
Source File: XTextAreaPeer.java From hottub with GNU General Public License v2.0 | 6 votes |
@Override protected void uninstallDefaults(JScrollPane c) { super.uninstallDefaults(c); JScrollBar vsb = scrollpane.getVerticalScrollBar(); if (vsb != null) { if (vsb.getBorder() == vsbBorder) { vsb.setBorder(null); } vsbBorder = null; } JScrollBar hsb = scrollpane.getHorizontalScrollBar(); if (hsb != null) { if (hsb.getBorder() == hsbBorder) { hsb.setBorder(null); } hsbBorder = null; } }
Example #25
Source File: MetalScrollBarUI.java From hottub with GNU General Public License v2.0 | 5 votes |
public Dimension getPreferredSize( JComponent c ) { if ( scrollbar.getOrientation() == JScrollBar.VERTICAL ) { return new Dimension( scrollBarWidth, scrollBarWidth * 3 + 10 ); } else // Horizontal { return new Dimension( scrollBarWidth * 3 + 10, scrollBarWidth ); } }
Example #26
Source File: ScrollablePopupMenu.java From jaamsim with Apache License 2.0 | 5 votes |
@Override public void layoutContainer(Container parent) { Insets insets = parent.getInsets(); // Set the bounds for the scroll bar JScrollBar scrollBar = getScrollBar(parent); int barWidth = 0; if (scrollBar != null) { barWidth = scrollBar.getPreferredSize().width; scrollBar.setBounds( parent.getWidth() - insets.right - barWidth, insets.top, barWidth, parent.getHeight() - insets.top - insets.bottom); } // Set the bounds for the other components int y = insets.top; if (scrollBar != null) { y -= scrollBar.getValue(); } for (Component comp : parent.getComponents()) { if (!comp.isVisible() || comp instanceof JScrollBar) continue; comp.setBounds( insets.left, y, parent.getWidth() - insets.left - insets.right - barWidth, comp.getPreferredSize().height); y += comp.getPreferredSize().height; } }
Example #27
Source File: ScrollablePopupMenu.java From jaamsim with Apache License 2.0 | 5 votes |
private static Dimension getSize(Container parent) { Dimension ret = new Dimension(); for (Component comp : parent.getComponents()) { if (!comp.isVisible() || comp instanceof JScrollBar) continue; ret.width = Math.max(ret.width, comp.getPreferredSize().width); ret.height += comp.getPreferredSize().height; } return ret; }
Example #28
Source File: SimpleXYChartUtils.java From visualvm with GNU General Public License v2.0 | 5 votes |
public static void setZoomingEnabled(JComponent chartUI, boolean enabled) { SimpleXYChart chart = (SimpleXYChart)chartUI.getClientProperty("chart"); // NOI18N if (chart.isZoomingEnabled() == enabled) return; else chart.setZoomingEnabled(enabled); JPanel sidePanel = (JPanel)chartUI.getClientProperty("sidePanel"); // NOI18N JPanel scrollerPanel = (JPanel)chartUI.getClientProperty("scrollerPanel"); // NOI18N if (enabled) { TransparentToolBar toolbar = new TransparentToolBar(false); for (Action action : chart.getActions()) toolbar.addItem(action); sidePanel.add(toolbar); JScrollBar scroller = chart.getScroller(); scroller.setSize(scroller.getPreferredSize()); scrollerPanel.add(scroller); chart.putClientProperty("scroller", scroller); // NOI18N } else { sidePanel.removeAll(); scrollerPanel.removeAll(); chart.putClientProperty("scroller", null); // NOI18N } sidePanel.setVisible(enabled); chartUI.doLayout(); chartUI.repaint(); }
Example #29
Source File: ScrollablePopupMenu.java From jaamsim with Apache License 2.0 | 5 votes |
public ScrollablePopupMenu(String label) { super(label); // First component is the scroll bar scrollBar = new JScrollBar(); scrollBar.setVisible(false); scrollBar.addAdjustmentListener(new AdjustmentListener() { @Override public void adjustmentValueChanged(AdjustmentEvent e) { doLayout(); repaint(); } }); super.add(scrollBar); // Use a customised LayoutManager to position the scroll bar correctly setLayout(new ScrollableMenuLayout()); // Respond to the mouse wheel addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent event) { int amount = (event.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) ? event.getUnitsToScroll() * scrollBar.getUnitIncrement() : (event.getWheelRotation() < 0 ? -1 : 1) * scrollBar.getBlockIncrement(); scrollBar.setValue(scrollBar.getValue() + amount); event.consume(); } }); }
Example #30
Source File: JScrollPaneOperator.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Scrolls pane to rectangle of a component. * * @param comp a subcomponent defining coordinate system. * @param x coordinate * @param y coordinate * @param width rectangle width * @param height rectangle height * @throws TimeoutExpiredException */ public void scrollToComponentRectangle(Component comp, int x, int y, int width, int height) { initOperators(); makeComponentVisible(); if (hScrollBarOper != null && hScrollBarOper.getSource().isVisible()) { hScrollBarOper.scrollTo(new ComponentRectChecker(comp, x, y, width, height, JScrollBar.HORIZONTAL)); } if (vScrollBarOper != null && vScrollBarOper.getSource().isVisible()) { vScrollBarOper.scrollTo(new ComponentRectChecker(comp, x, y, width, height, JScrollBar.VERTICAL)); } }