BorderLayout Swing

I m, using A BorderLayout. In the north position, I have a panel called panNorthwhere I add some component (for example, with one click I add one button in the next line (gridlayout)). In the main frame in the central part, I will add something later.

So, what is the problem, when I add new controls to panNorth, the size increases and takes center stage BorderLayout's. So I added JScrollPaneon the north side and added panNorthto Jscrollpane, but nothing else happened. The same thing happens again; the size JScrollPaneexpands to its original size panNorth, so it displays all the components, now the scroll bar is not fully used.

Therefore, please suggest me to make visible only 3 lines at a time.

+3
source share
1 answer

Try using:

jScrollPane.setPreferredSize(new Dimension(panNorth.getWidth(), desiredHeight));

This should force you JScrollPaneto keep your preferred size in the North panel.

+7
source

Source: https://habr.com/ru/post/1790619/


All Articles