【发布时间】:2012-01-21 07:21:49
【问题描述】:
我有一个 Jpanel,我在其中添加了许多组件(比如说 100 个 JButton)。 当我现在请求添加的组件的高度时,全部为 0。 代码来了:
void AddComponents(){
//add 100 Buttons to my jpanel
for (Component component : jpanel.getComponents()) {
Rectangle test = component.getBounds();
DebugTextArea.append("\nx: " + test.x + "- y:" + test.y +
"- height: " + test.height + "- width: " + test.width);
}
}
所有值都是 0。我知道这与绘制组件需要一些时间这一事实有关,但是我怎样才能获得高度,因为我需要组件的高度来将 VerticalScrollBar 设置为某一点。
有什么想法吗?
【问题讨论】:
-
请学习java命名约定并遵守它们
-
sry 下次我会努力做得更好
标签: java swing components jpanel paint