简体   繁体   English

BorderLayout Swing

[英]BorderLayout Swing

I m using A BorderLayout . 我正在使用A BorderLayout In the north position I m having a panel called panNorth , where I'm adding some component (say for one click I'm adding one button in the next row (gridlayout)). 在北方位置,我有一个名为panNorth的面板,我在那里添加了一些组件(比如我只是在下一行添加一个按钮(gridlayout))。 In the main frame in the center part I will add something later. 在中间部分的主框架中,我稍后会添加一些内容。

So what is my problem now is, when ever I'm adding new controls in panNorth the size getting increased and occupy the BorderLayout's center place. 那么我现在的问题是,当我在panNorth添加新的控件时,大小会增加并占据BorderLayout's中心位置。 So I added a JScrollPane in the north side and added the panNorth in Jscrollpane, but nothing different happened. 所以我在北侧添加了一个JScrollPane ,并在panNorth中添加了panNorth,但没有发生任何不同。 The same thing is happening again; 同样的事情再次发生; the size of the JScrollPane is expanding to the original size of the panNorth so it displays all the components, the scrollbar is not use full now. JScrollPane的大小正在扩展到panNorth的原始大小,因此它显示所有组件,滚动条现在不能使用。

So please suggest to me how to make visible only 3 rows at a time. 所以请向我建议如何一次只能看到3行。

Try using: 尝试使用:

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

This should force the JScrollPane to keep its preferred size in the North pane. 这应该强制JScrollPane在North窗格中保持其首选大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM