栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何调整滚动条在滚动窗格中的位置

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何调整滚动条在滚动窗格中的位置

这是我使用的实用程序类。可用于滚动到的顶部,底部,左侧,右侧或水平/垂直中心

JScrollPane

public final class ScrollUtil {    public static final int NONE = 0, TOP = 1, VCENTER = 2, BOTTOM = 4, LEFT = 8, HCENTER = 16, RIGHT = 32;    private static final int OFFSET = 100; // Required for hack (see below).    private ScrollUtil() {    }        public static void scroll(JComponent c, int part) {        scroll(c, part & (LEFT|HCENTER|RIGHT), part & (TOP|VCENTER|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);    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/507902.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号