使用JScrollPane的问题,纵向的滚动条出不来?

jindunfu jindunfu 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
import javax.swing.*;
import java.awt.*;

public class TestFlowLayout
extends JFrame {
JScrollPane jScrollPane1 = new JScrollPane();
JPanel jPanel1 = new JPanel();
FlowLayout flowLayout1 = new FlowLayout();
BorderLayout borderLayout1 = new BorderLayout();

public TestFlowLayout() {
try {
this.setSize(400, 300);
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}

private void jbInit() throws Exception {
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().setLayout(borderLayout1);
jPanel1.setLayout(flowLayout1);
flowLayout1.setAlignment(FlowLayout.LEFT);
for (int i = 9; i < 69; i++) {
jPanel1.add(new JButton("JButton" + (i + 1)), null);
}
jPanel1.setPreferredSize(new Dimension(380, -1));
this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jPanel1, null);
}

public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
e.printStackTrace();
}
TestFlowLayout frame = new TestFlowLayout();
frame.setVisible(true);
}

}
...全文
评论 5
收藏 已收藏
分享
返回顶部
jindunfu
Java SE 62,621 成员 307,251 内容