Re: [Layout] get position of component with getBounds()
markspace wrote:
public static void main(String args[]) {
SwingUtilities.invokeLater( new Runnable() {
dmoyne: Take special note of this call to 'invokeLater()', on which your code
post totally flaked.
Swing code must run on the EDT.
public void run()
{
dumpBounds( new GetBoundsTest(), 0 );
}
private void dumpBounds( Component comp, int level )
{
indent( level );
System.out.println( comp.getClass().getSimpleName()+": "
+comp.getBounds() );
if( comp instanceof Container ) {
Container cont = (Container) comp;
for( Component newC : cont.getComponents() ){
dumpBounds( newC, level+1 );
}
}
}
private void indent( int level ) {
for( int i = 0; i < level; i++ ) {
System.out.print( " " );
}
}
} );
}
}
--
Lew