tags:

views:

78

answers:

2

I need to create a panel where I can put some rectangles and it automatically reorder just inserting a scrollbar and growing up vertically. Also this panel can be resizable and again the rectangles must to be reordered to correctly be displayed inside the panel.

+1  A: 

Use a JScrollPane. If you never want a horizontal scroll bar you can add the following:

scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

(By default the scroll pane will add horizontal and vertical scroll bars when required.)

The scroll pane itself will only be resizeable if you add it to a Container with the appropriate layout manager; e.g.

JFrame frm = new JFrame();
frm.setLayout(new BorderLayout());
JScrollPane sp = new JScrollPane();
frm.add(sp, BorderLayout.CENTER); // Adding a component to the CENTER will cause the component to grow as the frame is resized.
Adamski
+1  A: 

If I understand the question you want components to wrap to the next line so that the panel grows vertically while the width remains fixed. If so then check out the WrapLayout

camickr