我正在尝试将几个面板添加到 JScrollpane 并依次添加到框架,但我无法滚动。这是代码。
first_panel = new JPanel();
first_panel.setBackground(Color.red);
second_panel = new JPanel();
second_panel.setBackground(Color.blue);
third_panel = new JPanel();
third_panel.setBackground(Color.green);
fourth_panel = new JPanel();
fourth_panel.setBackground(Color.red);
fifith_panel = new JPanel();
fifith_panel.setBackground(Color.blue);
six_panel = new JPanel();
six_panel.setBackground(Color.green);
final_panel = new JPanel();
final_panel.setLayout(null);
final_panel.setBackground(Color.gray);
final_panel.add(first_panel);
final_panel.add(second_panel);
final_panel.add(third_panel);
final_panel.add(fourth_panel);
final_panel.add(fifith_panel);
final_panel.add(six_panel);
first_panel.setBounds(10,10,200,100);
second_panel.setBounds(10,10,200,200);
third_panel.setBounds(10,10,200,300);
fourth_panel.setBounds(10,10,200,400);
fifith_panel.setBounds(10,10,200,500);
six_panel.setBounds(10,10,200,600);
panel_scroll = new JScrollPane(final_panel);
panel_scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
final_panel.setBounds(0,0,400,400);
// scroll_panel = new JPanel();
// scroll_panel.setLayout(null);
// scroll_panel.add(panel_scroll);
// panel_scroll.setBounds(0,0,400,400);
frame.getContentPane().add(panel_scroll);
有人可以帮我弄这个吗。提前致谢。