Column titles using center justification disappear when using JFC/Swing

Article ID: 1064
Last updated: 02 Feb, 2008
Article ID: 1064
Last updated: 02 Feb, 2008
Revision: 1
Views: 2974
Posted: 21 Aug, 1998
by Dean J.
Updated: 02 Feb, 2008
by Dean J.
Problem


Column titles using center justification disappear when implementing a grid using JFC/Swing. Equivalent AWT grids display the titles correctly.


Cause


The problem occurs in the drawImageLabel method of the GXLabel class. When the center alignment is used, the following code is not executed correctly within the current version of the JIT compiler (JDK 1.1.6). The JIT runs by default when Java is executed on Win32 platforms.

xp += width/2-fm.stringWidth(str)/2;

g.drawString(str, xp, y-fm.getDescent() + (int)(height+nTextHigh)/2);

The value returned for the xp variable is not correct. The value returned for y-fm.getDescent() + (int)(height+nTextHigh)/2 is also incorrect.

It appears that the JIT may be attempting to optimize the code, which is causing an error in the calculation.




Action


The problem can be solved by using the shift operation instead of the simple division originally used in the GXLabel class.

This change is equivalent in function to the original code, but is implemented to avoid the problem caused by JIT error.

A modified copy of the GXLabel.java is available below to temporarily modify the code until a new JIT is available which corrects this problem. To implement this modification, this file should be recompiled to replace the existing .class file in the Grid.J source code for JFC.

Download the modified GXLabel.java file
This article was:   Helpful | Not helpful
Report an issue
Article ID: 1064
Last updated: 02 Feb, 2008
Revision: 1
Views: 2974
Posted: 21 Aug, 1998 by Dean J.
Updated: 02 Feb, 2008 by Dean J.
Attached files
item GXLabel.java (13 kb) Download


Others in this category