具体代码
package org.example;
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
public static JFrame jFrame;
public static JPanel jPanel=new JPanel();
public static JScrollPane jScrollPane=new JScrollPane(jPanel,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
public static void main(String[] args) {
jFrame=new JFrame("测试滚动条界面");
jFrame.setSize(600,400);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setLocationRelativeTo(null);
//设置组件
jFrame.add(jScrollPane);
jPanel.setPreferredSize(new Dimension(800,2000));
jFrame.setVisible(true);
}
}
运行结果