Java Code Examples for javax.swing.JScrollBar

The following examples show how to use javax.swing.JScrollBar. These examples are extracted from open source projects. 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 Project: jdk8u-jdk   Source File: LWTextAreaPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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 Project: openjdk-jdk9   Source File: XTextAreaPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 3
Source Project: jdk8u-dev-jdk   Source File: XTextAreaPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 4
@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 5
@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 6
Source Project: seaglass   Source File: SeaGlassScrollPaneUI.java    License: Apache License 2.0 6 votes vote down vote up
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 7
Source Project: dragonwell8_jdk   Source File: Test6526631.java    License: GNU General Public License v2.0 6 votes vote down vote up
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
@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 9
Source Project: openjdk-8-source   Source File: Test7163696.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 10
Source Project: TencentKona-8   Source File: LWTextAreaPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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 11
Source Project: jdk8u_jdk   Source File: XTextAreaPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 12
@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 13
Source Project: TencentKona-8   Source File: XTextAreaPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 14
Source Project: openjdk-8   Source File: XTextAreaPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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 15
Source Project: openjdk-jdk8u   Source File: Test7163696.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 16
Source Project: TencentKona-8   Source File: Test8039464.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 17
Source Project: zap-extensions   Source File: JScrollPopupMenu.java    License: Apache License 2.0 6 votes vote down vote up
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 18
Source Project: jdk8u60   Source File: LWTextAreaPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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 19
Source Project: openjdk-jdk8u   Source File: LWTextAreaPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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 20
Source Project: jdk8u60   Source File: XTextAreaPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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 21
Source Project: jdk8u60   Source File: Test7163696.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 22
Source Project: hottub   Source File: XTextAreaPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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 23
Source Project: openjdk-8   Source File: LWScrollBarPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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 24
Source Project: openjdk-jdk9   Source File: LWTextAreaPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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 25
Source Project: netbeans   Source File: SmoothScrollPaneUI.java    License: Apache License 2.0 5 votes vote down vote up
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 26
private JScrollBar getScroller(int column) {
    for (Component component : scrollersPanel.getComponents()) {
        JScrollBar scroller = (JScrollBar)component;
        if (getColumn(scroller) == column) return scroller;
    }
    return null;
}
 
Example 27
/**
 * Maps {@code JScrollPane.setHorizontalScrollBar(JScrollBar)} through queue
 */
public void setHorizontalScrollBar(final JScrollBar jScrollBar) {
    runMapping(new MapVoidAction("setHorizontalScrollBar") {
        @Override
        public void map() {
            ((JScrollPane) getSource()).setHorizontalScrollBar(jScrollBar);
        }
    });
}
 
Example 28
Source Project: openjdk-jdk9   Source File: XTextAreaPeer.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see java.awt.peer.TextAreaPeer
 */
@Override
public Dimension getMinimumSize(int rows, int cols) {
    /*    Dimension d = null;
          if (jtext != null) {
          d = jtext.getMinimumSize(rows,cols);
          }
          return d;
    */

    int vsbwidth=0;
    int hsbheight=0;

    JScrollBar vsb = textPane.getVerticalScrollBar();
    if (vsb != null) {
        vsbwidth = vsb.getMinimumSize().width;
    }

    JScrollBar hsb = textPane.getHorizontalScrollBar();
    if (hsb != null) {
        hsbheight = hsb.getMinimumSize().height;
    }

    Font f = jtext.getFont();
    FontMetrics fm = jtext.getFontMetrics(f);

    return new Dimension(fm.charWidth('0') * cols + /*2*XMARGIN +*/ vsbwidth,
                         fm.getHeight() * rows + /*2*YMARGIN +*/ hsbheight);
}
 
Example 29
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 30
Source Project: visualvm   Source File: ChartPanel.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void scroll(JScrollBar scrollBar, MouseWheelEvent e) {
    if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
        int unitsToScroll = e.getUnitsToScroll();
        int direction = unitsToScroll < 0 ? -1 : 1;
        if (unitsToScroll != 0) {
            int increment = scrollBar.getUnitIncrement(direction);
            int oldValue = scrollBar.getValue();
            int newValue = oldValue + increment * unitsToScroll;
            newValue = Math.max(Math.min(newValue, scrollBar.getMaximum() -
                    scrollBar.getVisibleAmount()), scrollBar.getMinimum());
            if (oldValue != newValue) scrollBar.setValue(newValue);
        }
    }
}