滚动问题 - 当我按下时不滚动

发布于 2024-11-03 02:51:38 字数 1089 浏览 1 评论 0原文

我在 Java 中遇到了奇怪的问题。我有 JScrollPane

paneScroll=new JScrollPane(nav,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

,其中 nav 是 JPanel

public class ScrollableNavigationPanelZones extends JPanel {
    private ButtonGroup buttonGroup = new ButtonGroup();
    private static final long serialVersionUID = -455651438039139284L;
    protected JViewport viewport;
    private JPanel panel;

    private int offset = 100;

    public ScrollableNavigationPanelZones() {
        super();
        setLayout(new BorderLayout());

        panel = new JPanel();
        panel.setPreferredSize(new Dimension(0,160));
        FlowLayout fl = new FlowLayout();
        fl.setVgap(5);
        fl.setAlignment(FlowLayout.LEFT);
        panel.setLayout(fl);
        add(panel,BorderLayout.CENTER);



    }
    }

,它在右侧显示滚动,但没有那个可以移动的小框(我在滚动的顶部和底部有箭头,但当我按下时我无法滚动)。当我更改 ScrollableNavigationPanelZones panel.setPreferredSize(new Dimension(0,16000)); 时它可以工作,但显示空白。为什么 JScrollPane 不读取面板的真实高度?什么是错误? 有人可以帮忙吗?

I have strange problem in Java. I have JScrollPane

paneScroll=new JScrollPane(nav,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

where nav is JPanel

public class ScrollableNavigationPanelZones extends JPanel {
    private ButtonGroup buttonGroup = new ButtonGroup();
    private static final long serialVersionUID = -455651438039139284L;
    protected JViewport viewport;
    private JPanel panel;

    private int offset = 100;

    public ScrollableNavigationPanelZones() {
        super();
        setLayout(new BorderLayout());

        panel = new JPanel();
        panel.setPreferredSize(new Dimension(0,160));
        FlowLayout fl = new FlowLayout();
        fl.setVgap(5);
        fl.setAlignment(FlowLayout.LEFT);
        panel.setLayout(fl);
        add(panel,BorderLayout.CENTER);



    }
    }

and it shows scroll on right side but doesn't have that small box which to move ( I have arrows on top and bottom of scroll, but when I press I cannot scroll ). When I change in ScrollableNavigationPanelZones panel.setPreferredSize(new Dimension(0,16000)); it works but shows empty space. Why JScrollPane doesn't read real height of panel ? What is mistake ?
Can anybody help please ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花伊自在美 2024-11-10 02:51:38

仅当有需要滚动的内容时,即面板的首选高度超过滚动窗格的实际高度时,才会显示滚动框。当然,如果将首选高度设置为 16000,并且面板未用控件填充所有 16000 像素,则会显示大量空白空间。

如果面板适合滚动窗格,则默认情况下隐藏滚动条。标志 VERTICAL_SCROLLBAR_​​ALWAYS 意味着滚动条始终可见,即使不需要。如果将面板高度设置为 160 像素并且滚动窗格更大,您会看到滚动条(因为它始终存在),但看不到滚动框(因为实际上没有任何内容可以滚动)。

有点奇怪的是,即使没有什么可滚动的,滚动条上的向上和向下按钮也是可点击的。通常在这种情况下它们应该显示为灰色。也许 JScrollPane 中有一些额外的参数用于此......

The scroll box is displayed only if there is something to scroll, i.e. if the preferred height of the panel exceeds the actual height of the scroll pane. Of course, if you set the preferred height to 16000 it will show much of empty space if the panel doesn't fill all the 16000 pixels with controls.

If the panel fits in the scroll pane, the scroll bar is by default hidden. The flag VERTICAL_SCROLLBAR_ALWAYS implies that the scroll bar is visible always, even if not needed. If you set the panel height to 160 pixels and the scroll pane is larger, you see the scroll bar (because it's ALWAYS) but no scroll box (because there is actually nothing to scroll).

It's a bit strange that the up and down buttons on the scroll bar are clickable even if there is nothing to scroll. Usually they should be greyed out in this case. Maybe there is some additional parameter in JScrollPane for this...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文