I have almost completed my Java application designed in Netbeans using JFrame
. The mistake I have made is that I have put all my components directly on the frame rather than a JPanel
. Now I want to make the frame scrollable, but I don't know how I can transfer all my components to a scroll pane from the frame. Any other way of making the frame scrollable?
Use the following code
JScrollPane pane = new JScrollPane(getContentPane(),
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
this.setContentPane(pane);
and add a preferred size to your content pane
setPreferredSize(new Dimension(900, 900));
I got the same problem and the above code worked for me.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.