【问题标题】:JScrollPane not working with JPanel and JFrameJScrollPane 不能与 JPanel 和 JFrame 一起使用
【发布时间】:2020-04-15 07:46:05
【问题描述】:

对于我的代码,我做了类似的事情:

Jframe frame = new JFrame();
JPanel panel = new JPanel();

JButton button = new JButton();
// after locating and resizing buttons...
panel.add(button);

// and after many codes about buttons and labels...

frame.add(panel);

JScrollPane scroll = new JScrollPane(panel);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
frame.add(scroll);

据我所知,这应该是正确的,但我无法滚动。 滚动条内的灰色条不见了。

感谢您的关注和时间!

image for better idea of what's happening to my code.

【问题讨论】:

    标签: java swing jframe jpanel jscrollpane


    【解决方案1】:

    如果您阅读https://docs.oracle.com/javase/tutorial/uiswing/components/scrollpane.html 上有关滚动窗格的官方教程,他们会注意到这些政策:

    VERTICAL_SCROLLBAR_​​ALWAYS

    HORIZONTAL_SCROLLBAR_​​ALWAYS

    始终显示滚动条。如果视口是,旋钮会消失 大到足以显示整个客户端。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多