JComponent 绘制前的高度
我有一个 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到某一点。
有什么想法吗?
I have a Jpanel where I add many Components (lets say 100 JButtons).
When I now request the height of the added Components there are all 0.
Here come Code:
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);
}
}
All values are 0. I know it hase something to do with the fact that the painting of the components will take some time, but how can I get the height becouse I will need the height of the Components to set the VerticalScrollBar to a certain point.
any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
带有按钮的面板(又名:显示)
我需要组件的高度来设置 VerticalScrollBar - 不,你不需要(假设这是 JScrollPane 的滚动条,其中包含组件实现后
I will need the height of the Components to set the VerticalScrollBar - no you don't (assuming that's the scrollbar of a JScrollPane which contains the panel with the buttons
after the component is realized (aka: shown)