Example usage for javax.swing JViewport toViewCoordinates

List of usage examples for javax.swing JViewport toViewCoordinates

Introduction

In this page you can find the example usage for javax.swing JViewport toViewCoordinates.

Prototype

public Point toViewCoordinates(Point p) 

Source Link

Document

Converts a point in pixel coordinates to view coordinates.

Usage

From source file:Main.java

public static boolean canVScroll(JViewport viewport) {
    JScrollPane scrollPane = (JScrollPane) viewport.getParent();
    Rectangle availR = scrollPane.getBounds();

    Component view = viewport.getView();
    Dimension viewPrefSize = view != null ? view.getPreferredSize() : new Dimension(0, 0);
    Dimension extentSize = viewport.toViewCoordinates(availR.getSize());

    boolean canVScroll = true;
    if (view instanceof Scrollable)
        canVScroll = !((Scrollable) view).getScrollableTracksViewportHeight();
    if (canVScroll && (viewPrefSize.height <= extentSize.height))
        canVScroll = false;/*from www .j a va 2s.com*/

    return canVScroll;
}

From source file:Main.java

public static boolean canHScroll(JViewport viewport) {
    JScrollPane scrollPane = (JScrollPane) viewport.getParent();
    Rectangle availR = scrollPane.getBounds();

    Component view = viewport.getView();
    Dimension viewPrefSize = view != null ? view.getPreferredSize() : new Dimension(0, 0);
    Dimension extentSize = viewport.toViewCoordinates(availR.getSize());

    boolean canHScroll = true;
    if (view instanceof Scrollable)
        canHScroll = !((Scrollable) view).getScrollableTracksViewportWidth();
    if (canHScroll && (viewPrefSize.width <= extentSize.width))
        canHScroll = false;//from w ww.j  a v  a 2  s . c  om

    return canHScroll;
}