我想在 gui 中的框架右侧添加一个滚动 Pane 。有人可以吗 给我代码吗?我不知道除了javax.swing之外是否还需要导入其他东西。下面是主要的。我希望你能读一下。谢谢。
import javax.swing.JFrame;
import javax.swing.*;
public class School {
public static void main (String[] args) {
Test t= new Test();
JFrame f = new JFrame ("Calculus");
f.add(t);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize (530, 700);
f.setVisible (true);
}
}
最佳答案
创建一个 JPanel
,然后将其添加到 JScrollPane
,然后将此 JScrollPane
添加到您的 JFrame
例如:
JFrame f = new JFrame ("Calculus");
JPanel panel = new JPanel();
Test t= new Test();
panel.add(t);// add the component you want to be scrolling to the scroll pane.
JScrollPane scrollFrame = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
f.add(scrollFrame);
关于java - 如何向我的框架添加滚动 Pane ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23111807/