getPreferredSize()、setPreferredSize()、getSize()、setSize()、revalidate()、pack()

有时候对容器内的组件期望尺寸信息进行了改变setPreferredSize(),却没有立即看到效果,

那可能是由于布局管理器缓存了布局信息,这时候我们就需要使布局失效,迫使他在下一次

重绘的时候重新计算排列容器内的组件。比较常用的方法是调用组件的方法revalidate ,这
样会使调用该方法的组件与该组件外层的所有容器都标记为需要重新布局。

 

1 /**
2 * Causes this component to be sized to fit the preferred size.
3 */
4 public function pack():void
5 {
6    setSize(getPreferredSize());
7 }

 

 1 /**
 2 * layout this container
 3 */
 4 public function doLayout():void
 5 {
 6    if(isVisible())
 7    {
 8       layout.layoutContainer(this);
 9    }
10 }

 

 1 UIManager.setLookAndFeel(new MusicLookAndFeel(getSkinProxy()));
 2 AsWingUtils.updateChildrenUI(app); 
 3 
 4 //Component.getUI().getPreferredSize(Component);
 5 //Component.getPreferredSize();
 6 //Component.setSize(new IntDimension(w, h));
 7 Container.pack();
 8 Container.setSize(new IntDimension(w, h));
 9 Container.doLayout();
10 Container.revalidate();
11 trace (Container.getPaintBounds(), Container.getSize(), Container.getPreferredSize());

 

posted @ 2012-01-31 22:31  ddw1997  阅读(2342)  评论(0编辑  收藏  举报