简体   繁体   中英

Wait till repaint Component is finished

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM