I have a ScrollPane with a JPanel in it and I add about 200 Components in the JPanel. Know I want that the Vertical-Slider move to a specific Component.
But the problem is that when I am Calling:
myButton.scrollRectToVisible(myButton.getBounds());
getBounds() gives me width and height back with 0.
Obviously the elements are still not painted. How can I wait till the repaint() method has finished all it’s work, so that I can then do the scrollRectToVisible()?
EDIT:
Maybe it help if I gave a Short Example of my Code:
addElementsToPanel(); //function where I add Elements to the Panel
myJPanel.revalidate();
myJPanel.repaint();
myButton.scrollRectToVisible(myButton.getBounds());
SwingUtilities.invokeLater()?