Pages

about my opensource eclipse java applications recently i'm studying GWT and Android

Sunday, August 07, 2005

Customize BorderLayout of Draw2D


If you customized BorderLayout.java ,you could do such things.

Certainly,If you overwrited getPreferedSize(),and you could do.
But If you did customize BorderLayout,You could control center figure of BorderLayout.
It's simple and usefull.

I copy from BorderLayout.java to CustomBorderLayout.java

and new field.
and create both of get and set methods.
private boolean stretchCenterWidth=true;
private boolean stretchCenterHeight=false;


and ,on layout() methods,
I replace code to when stretchCenter* is true,layoutmanager stretch figure width or height.
if(!stretchCenterHeight){
if (childSize.height <>
area.y += (area.height - childSize.height) / 2;
area.height = childSize.height;
}
}

if(!stretchCenterWidth){
if (childSize.width <>
area.x += (area.width - childSize.width) / 2;
area.width = childSize.width;
}
}
finally use call in your program like this.
CustomBorderLayout layout=new CustomBorderLayout(); layout.setStretchCenterWidth(true);
layout.setStretchCenterHeight(true);


FullCode
http://cvs.sourceforge.jp/cgi-bin/viewcvs.cgi/akjrcp/draw2dexample/src/example/draw2d/CustomBorderLayoutTest.java?rev=1.1&content-type=text/vnd.viewcvs-markup