1、设置容器位置时记录容器最原始的位置。
JComponent c =。。。。;
c.putClientProperty("OriginalBounds",new Rectangle(.....))
2、某个容器的大小改变时,从最外面的容器开始这各个面板中子容器的新位置。
3、获取父容器原始大小
Rectangle containerOriginalBounds = (Rectangle) c.getClientProperty("OriginalBounds");
4、获取父控件现宽与原宽的比例
float scaleH = c.getWidth() / containerOriginalBounds.width;
float scaleV = c.getHeight() / containerOriginalBounds.height;
5、逐个设置父控件里的子控件当前的位置大小
int count = c.getComponentCount();
for (int i = 0; i < count; ++i) {
JComponent item = (JComponent) c.getComponent(i);
Constraints cons = (Constraints) item.getClientProperty("TVLayoutConstraints");
6、获取子控件原来的大小和位子,根据父控件现宽与原宽的比例,设置子控件新的位置