JScrollPane 不适用于 JPanel 和 JFrame
JScrollPane not working with JPanel and JFrame
对于我的代码,我做了类似的事情:
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);
据我所知,这应该是正确的,但我无法滚动。 滚动条里面的灰色条不见了。
感谢您的关注和时间! <3
image for better idea of what's happening to my code.
如果您在 https://docs.oracle.com/javase/tutorial/uiswing/components/scrollpane.html 上阅读有关滚动窗格的官方教程,他们会注意到以下政策:
VERTICAL_SCROLLBAR_ALWAYS
HORIZONTAL_SCROLLBAR_ALWAYS
Always display the scroll bar. The knob disappears if the viewport is
large enough to show the whole client.
对于我的代码,我做了类似的事情:
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);
据我所知,这应该是正确的,但我无法滚动。 滚动条里面的灰色条不见了。
感谢您的关注和时间! <3
image for better idea of what's happening to my code.
如果您在 https://docs.oracle.com/javase/tutorial/uiswing/components/scrollpane.html 上阅读有关滚动窗格的官方教程,他们会注意到以下政策:
VERTICAL_SCROLLBAR_ALWAYS
HORIZONTAL_SCROLLBAR_ALWAYS
Always display the scroll bar. The knob disappears if the viewport is large enough to show the whole client.