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?
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)