当前位置: 首页>>代码示例>>Java>>正文


Java JComponent.scrollRectToVisible方法代码示例

本文整理汇总了Java中javax.swing.JComponent.scrollRectToVisible方法的典型用法代码示例。如果您正苦于以下问题:Java JComponent.scrollRectToVisible方法的具体用法?Java JComponent.scrollRectToVisible怎么用?Java JComponent.scrollRectToVisible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JComponent的用法示例。


在下文中一共展示了JComponent.scrollRectToVisible方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: scroll

import javax.swing.JComponent; //导入方法依赖的package包/类
/**
 * Scroll to specified location. e.g.
 * <tt>scroll(component, LEFT, BOTTOM);</tt>.
 *
 * @param c
 *            JComponent to scroll.
 * @param horizontal
 *            Horizontal location. Should take the value: LEFT, HCENTER or
 *            RIGHT.
 * @param vertical
 *            Vertical location. Should take the value: TOP, VCENTER or
 *            BOTTOM.
 */
public static void scroll(JComponent c, int horizontal, int vertical){
	Rectangle visible=c.getVisibleRect();
	Rectangle bounds=c.getBounds();
	
	switch(vertical){
	case TOP:
		visible.y=0;
		break;
	case VCENTER:
		visible.y=(bounds.height-visible.height)/2;
		break;
	case BOTTOM:
		visible.y=bounds.height-visible.height+OFFSET;
		break;
	}
	
	switch(horizontal){
	case LEFT:
		visible.x=0;
		break;
	case HCENTER:
		visible.x=(bounds.width-visible.width)/2;
		break;
	case RIGHT:
		visible.x=bounds.width-visible.width+OFFSET;
		break;
	}
	
	// When scrolling to bottom or right of viewport, add an OFFSET value.
	// This is because without this certain components (e.g. JTable) would
	// not scroll right to the bottom (presumably the bounds calculation
	// doesn't take the table header into account.  It doesn't matter if
	// OFFSET is a huge value (e.g. 10000) - the scrollRectToVisible method
	// still works correctly.
	
	c.scrollRectToVisible(visible);
}
 
开发者ID:LapisSea,项目名称:OpenGL-Bullet-engine,代码行数:51,代码来源:ScrollUtil.java

示例2: tick

import javax.swing.JComponent; //导入方法依赖的package包/类
@Override public void tick(double progress) {
    double nextZoom = progress >= 1.0 ? targetZoom :
        (sourceZoom + progress * (targetZoom - sourceZoom));

    Scene scene = getScene();
    JComponent view = scene.getView ();

    if (view != null) {
        Point viewLocation = view.getVisibleRect ().getLocation();
        Dimension viewSize = view.getVisibleRect ().getSize();
        Point oldCenter = scene.convertSceneToView (center);

        ((DependencyGraphScene)scene).setMyZoomFactor (nextZoom);
        scene.validate (); // HINT - forcing to change preferred size of the JComponent view

        Point newCenter = scene.convertSceneToView (center);
        Rectangle viewBounds = view.getVisibleRect();
        Point visibleCenter = new Point((int)viewBounds.getCenterX(), (int)viewBounds.getCenterY());
        newCenter.x += Math.round((newCenter.x - visibleCenter.x) * progress);
        newCenter.y += Math.round((newCenter.y - visibleCenter.y) * progress);

        view.scrollRectToVisible (new Rectangle (
                newCenter.x - oldCenter.x + viewLocation.x,
                newCenter.y - oldCenter.y + viewLocation.y,
                viewSize.width,
                viewSize.height
        ));
    } else {
        ((DependencyGraphScene)scene).setMyZoomFactor (nextZoom);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:CenteredZoomAnimator.java

示例3: restoreScrollPosition

import javax.swing.JComponent; //导入方法依赖的package包/类
/**
 * Restore stored scroll position.
 */
private void restoreScrollPosition(boolean delayScrollWithMarkingDirtyRegion) {
    if (visibleTreePosition != null) {
        JTree tree = getJTree();
        if (tree != null) {
            int row = tree.getRowForPath(visibleTreePosition.getPath());
            if (row != -1) {
                Rectangle bounds = tree.getRowBounds(row);
                if (bounds != null) {
                    int scrollY = bounds.y - visibleTreePosition.getOffset();
                    JViewport viewport = mainScrollPane.getViewport();
                    Rectangle rect = viewport.getViewRect();
                    rect.y = scrollY;
                    if (!rect.isEmpty()) {
                        JComponent view = (JComponent) viewport.getView();
                        if (delayScrollWithMarkingDirtyRegion) {
                            RepaintManager.currentManager(viewport).addDirtyRegion(
                                    view,
                                    rect.x, rect.x, rect.width, rect.height);
                        }
                        ignoreScrollAdjustment = true;
                        try {
                            view.scrollRectToVisible(
                                    rect);
                        } finally {
                            ignoreScrollAdjustment = false;
                        }
                    }
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:DebuggingViewComponent.java

示例4: moveVisibleRect

import javax.swing.JComponent; //导入方法依赖的package包/类
private void moveVisibleRect(Point center) {
    JComponent component = scene.getView();
    if (component == null) {
        return;
    }
    double zoomFactor = scene.getZoomFactor();
    Rectangle bounds = scene.getBounds();
    Dimension size = getSize();

    double sx = bounds.width > 0 ? (double) size.width / bounds.width : 0.0;
    double sy = bounds.width > 0 ? (double) size.height / bounds.height : 0.0;
    double scale = Math.min(sx, sy);

    int vw = (int) (scale * bounds.width);
    int vh = (int) (scale * bounds.height);
    int vx = (size.width - vw) / 2;
    int vy = (size.height - vh) / 2;

    int cx = (int) ((double) (center.x - vx) / scale * zoomFactor);
    int cy = (int) ((double) (center.y - vy) / scale * zoomFactor);

    Rectangle visibleRect = component.getVisibleRect();
    visibleRect.x = cx - visibleRect.width / 2;
    visibleRect.y = cy - visibleRect.height / 2;
    component.scrollRectToVisible(visibleRect);

    this.repaint();
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:29,代码来源:ExtendedSatelliteComponent.java

示例5: pan

import javax.swing.JComponent; //导入方法依赖的package包/类
private boolean pan (Widget widget, Point newLocation) {
    if (scrollPane == null  ||  scene != widget.getScene ())
        return false;
    newLocation = scene.convertSceneToView (widget.convertLocalToScene (newLocation));
    SwingUtilities.convertPointToScreen (newLocation, scene.getView ());
    JComponent view = scene.getView ();
    Rectangle rectangle = view.getVisibleRect ();
    rectangle.x += lastLocation.x - newLocation.x;
    rectangle.y += lastLocation.y - newLocation.y;
    view.scrollRectToVisible (rectangle);
    lastLocation = newLocation;
    return true;
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:14,代码来源:CustomizablePanAction.java

示例6: moveVisibleRect

import javax.swing.JComponent; //导入方法依赖的package包/类
private void moveVisibleRect(Point center) {
    JComponent component = scene.getView();
    if (component == null) {
        return;
    }
    double zoomFactor = scene.getZoomFactor();
    Rectangle bounds = scene.getBounds();
    Dimension size = getSize();

    double sx = bounds.width > 0 ? (double) size.width / bounds.width : 0.0;
    double sy = bounds.width > 0 ? (double) size.height / bounds.height : 0.0;
    double scale = Math.min(sx, sy);

    int vw = (int) (scale * bounds.width);
    int vh = (int) (scale * bounds.height);
    int vx = (size.width - vw) / 2;
    int vy = (size.height - vh) / 2;

    int cx = (int) ((double) (center.x - vx) / scale * zoomFactor);
    int cy = (int) ((double) (center.y - vy) / scale * zoomFactor);

    Rectangle visibleRect = component.getVisibleRect();
    visibleRect.x = cx - visibleRect.width / 2;
    visibleRect.y = cy - visibleRect.height / 2;
    component.scrollRectToVisible(visibleRect);

}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:28,代码来源:ExtendedSatelliteComponent.java

示例7: centerSelection

import javax.swing.JComponent; //导入方法依赖的package包/类
private void centerSelection() {
    Point sceneCenter = null;
    Collection<CfgNode> nodes = this.selectedNodes;
    if (nodes.size() == 0) {
        nodes = this.getNodes();
    }

    for (CfgNode n : nodes) {
        if (sceneCenter == null) {
            sceneCenter = this.findWidget(n).getLocation();
            continue;
        }
        Point location = this.findWidget(n).getLocation();
        sceneCenter.x = (location.x + sceneCenter.x) / 2;
        sceneCenter.y = (location.y + sceneCenter.y) / 2;
    }

    JComponent view = this.getView();
    if (view != null) {
        Rectangle viewBounds = view.getVisibleRect();

        Point viewCenter = this.convertSceneToView(sceneCenter);

        view.scrollRectToVisible(new Rectangle(
                viewCenter.x - viewBounds.width / 2,
                viewCenter.y - viewBounds.height / 2,
                viewBounds.width,
                viewBounds.height));
    }
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:31,代码来源:CfgScene.java

示例8: scroll

import javax.swing.JComponent; //导入方法依赖的package包/类
public void scroll(JComponent component) {
    component.scrollRectToVisible(currentDragRect);            
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:4,代码来源:DragManager.java

示例9: focusGained

import javax.swing.JComponent; //导入方法依赖的package包/类
@Override
public void focusGained(FocusEvent e) {
    JComponent c = (JComponent) e.getComponent();
    c.scrollRectToVisible(new Rectangle(0, 0, c.getWidth(), c
            .getHeight()));
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:7,代码来源:TableViewPreferenciesDialog.java


注:本文中的javax.swing.JComponent.scrollRectToVisible方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。