可滚动的JPanel [英] Scrollable JPanel

查看:123
本文介绍了可滚动的JPanel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使JPanel可滚动?我使用

How to make a JPanel scrollable? I implemented the scrollable interface yet when adding it to the containing panel with

tabbedPane.add("Editor", new JScrollPane(storeyEditor = new MNScrollablePanel()));

无效工作

代码:

public class MNScrollablePanel extends JPanel implements Scrollable {

    public Dimension getPreferredScrollableViewportSize() {
        return getPreferredSize();
    }

    public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
        return 10;
    }

    public boolean getScrollableTracksViewportHeight() {
        return false;
    }

    public boolean getScrollableTracksViewportWidth() {
        return false;
    }

    public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
        return 10;
    }
}


推荐答案

你必须使用 JScrollPane 。然后调用 setViewportview(Component);

You have to use a JScrollPane. And then call the setViewportview(Component);

您不必实现可滚动,JPanel已全部可滚动

You don't have to implement scrollable, JPanel is allready scrollable

这篇关于可滚动的JPanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆