java – BorderLayout Swing

I'm using a borderlayout In the north, I have a panel called pannorth, where I add some components (for example, I just add a grid layout on the next line) In the middle part of the main frame, I'll add something later

So my problem now is that when I add a new control in pannorth, the size will increase and occupy the central position of borderlayout So I added a JScrollPane on the north side and pannorth in JScrollPane, but there was no difference The same thing happens again; JScrollPane is expanding to the original size of pannorth, so it displays all components. The scroll bar is not available now

So please advise me how to see only three lines at a time

Solution

Try using:

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

This should force the JScrollPane to maintain its preferred size in the North pane

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>