AWT: TextField.getPreferredSize ()

U verdier philippe verdier at ditv-philips.fr
Thu Aug 13 06:08:16 PDT 1998


The 'getPreferredSize()' method of the 'TextField' class
always return 'text width = 50' whatever the string length !

A simple solution is to replace:

public Dimension getPreferredSize() {
	int cx = 50;
	int cy = 20;
	if ( font != null ){
		FontMetrics fm = getFontMetrics( font);
//		cx = Math.max( cx, fm.stringWidth( label));
		cy = Math.max( cy, 3*fm.getHeight()/2 );
	}
	return new Dimension( cx, cy);
}

.... by:

public Dimension getPreferredSize() {
	return getMinimumSize (cols);
}

Regards


More information about the kaffe mailing list