Leo*_*eon 1 java swing components paint jpanel
我有一个Jpanel,我添加了许多组件(比方说100 JButtons).当我现在请求添加的组件的高度时,全部为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);
}
}
Run Code Online (Sandbox Code Playgroud)
所有的值都是0.我知道这与组件的绘制需要一些时间有关,但是如何获得高度因为我将需要组件的高度来将VerticalScrollBar设置为某个点.
任何的想法?
我将需要组件的高度来设置VerticalScrollBar - 不,你不要(假设这是包含带按钮的面板的JScrollPane的滚动条)
button.scrollRectToVisible(button.getBounds())
Run Code Online (Sandbox Code Playgroud)
组件实现后(又名:显示)
| 归档时间: |
|
| 查看次数: |
108 次 |
| 最近记录: |