我正在尝试将滚动条放入 JPanel 中。
我把我的代码放在 public static void main 上。
public static void main(String[] args) {
JFrame frame = new JFrame("Outil Replacement");
frame.setSize(930, 610);
frame.setPreferredSize(new Dimension(930,400));
JScrollPane scrollPane = new JScrollPane();
scrollPane.setWheelScrollingEnabled(true);
frame.add(scrollPane);
frame.setContentPane(new Replacement().panelMain);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
它什么也没做。
只是一个表单 View 。
有人有解决办法吗?
最佳答案
您宁愿将目标 JPanel
设置为 JScrollPane
的 视口(viewport) View ,然后添加 JScrollPane
,例如这:
JScrollPane scrollPane = new JScrollPane(new Replacement().panelMain);
scrollPane.setWheelScrollingEnabled(true);
frame.setContentPane(scrollPane);
关于java - 如何在面板中添加滚动 Pane ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42553270/