Reputation: 51
I'm trying to put a scrollbar in a JPanel.
I put my code on 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);
}
It does nothing.
Just a form view.
Is someone have a solution ?
Upvotes: 0
Views: 408
Reputation: 17534
You rather set the target JPanel
as the JScrollPane
's viewport view then add the JScrollPane
, like this :
JScrollPane scrollPane = new JScrollPane(new Replacement().panelMain);
scrollPane.setWheelScrollingEnabled(true);
frame.setContentPane(scrollPane);
See : JScrollPane(java.awt.Component)
And : How to Use Scroll Panes
Upvotes: 2