set JViewport View Port Position - Java Swing

Java examples for Swing:JViewport

Description

set JViewport View Port Position

Demo Code


//package com.java2s;

import java.awt.Point;
import java.awt.Rectangle;

import javax.swing.JViewport;

public class Main {
    private static void setViewPortPosition(JViewport viewport,
            Rectangle position) {
        // The location of the viewport relative to the object
        Point pt = viewport.getViewPosition();

        // Translate the cell location so that it is relative
        // to the view, assuming the northwest corner of the
        // view is (0,0)
        position.setLocation(position.x - pt.x, position.y - pt.y);

        // Scroll the area into view
        viewport.scrollRectToVisible(position);
    }/*w  w w  .java2 s  . c o  m*/
}

Related Tutorials