Java JViewport setViewPortPosition(JViewport viewport, Rectangle position)

Here you can find the source of setViewPortPosition(JViewport viewport, Rectangle position)

Description

set View Port Position

License

Open Source License

Declaration

private static void setViewPortPosition(JViewport viewport, Rectangle position) 

Method Source Code

//package com.java2s;
/*//from w  w w .j  av a 2s.c o m
 *     GENESE - Gerador de N?meros e Estat?sticas para Mega-Sena
 *     Copyright (C)  2016  Rafael Teixeira
 *     rafaelfst@live.com
 *
 *     GENESE ? um software livre: voc? pode redistribu?-lo e/ou modific?-lo
 *     dentro dos termos da Licen?a P?blica Geral GNU como publicada pela
 *     Funda??o do Software Livre (FSF), na vers?o 3 da Licen?a, ou
 *     (na sua opini?o) qualquer vers?o posterior.
 *
 *     Este programa ? distribu?do na esperan?a de que possa ser ?til,
 *     mas SEM NENHUMA GARANTIA; sem uma garantia impl?cita de ADEQUA??O
 *     a qualquer MERCADO ou APLICA??O EM PARTICULAR. Veja a
 *     Licen?a P?blica Geral GNU para maiores detalhes.
 *
 *     Voc? deve ter recebido uma c?pia da Licen?a P?blica Geral GNU junto
 *     com este programa. Se n?o, veja <http://www.gnu.org/licenses/>.
 */

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);
    }
}

Related

  1. canHScroll(JViewport viewport)
  2. canScroll(JViewport viewport)
  3. fixScrollRendering(JViewport viewport)
  4. synchronizeView(final JViewport masterViewport, final JViewport slaveViewport, final int orientation)