【发布时间】:2017-08-20 07:56:05
【问题描述】:
我对 Java Swing 还是很陌生。有人可以帮我弄清楚我做错了什么吗?请在任何必要的地方纠正我。这段代码的很大一部分是反复试验。
我有一个框架,其中包含一个 JPanel。 JPanel 使用“GridBag”布局。如图所示,包含的代码围绕右侧的子 JPanel 旋转。出于某种原因,我的垂直滚动条似乎无法正常工作。
这是感兴趣的代码:
/// GridBagConstraints
GridBagConstraints gbc = new GridBagConstraints();
// parent jpanel for scrollpane
scrollPanel = new JPanel();
scrollPanel.setLayout(new BorderLayout());
gbc.gridx = 1;
gbc.gridy = 0;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
add(scrollPanel, gbc);
// content jpanel for scrollpane
scrollPaneContent = new JPanel();
scrollPaneContent.setLayout(new GridLayout(0, 1, 0, 1));
// scrollPane
scrollPane = new JScrollPane();
scrollPane.setBorder(BorderFactory.createEmptyBorder(0,30,0,0));
scrollPane.setViewportView(scrollPaneContent);
scrollPanel.add(scrollPane, BorderLayout.PAGE_START);
这是程序目前的样子。 你可以看到刚刚离开屏幕的数字:
非常感谢任何帮助!谢谢。
【问题讨论】:
-
如需尽快获得更好的帮助,请发帖minimal reproducible example 或Short, Self Contained, Correct Example。
标签: java swing jscrollpane