Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NullPointerException when setFont()

4 views
Skip to first unread message

Pierre

unread,
Aug 13, 2004, 3:38:35 AM8/13/04
to
Hello,
I'm trying to set font of a JTable but the method setFont(Font)
doesn't seems to work in my case.
Here is my code :
setFont(Font.getFont("Arial"));
System.out.println(isFontSet());
System.out.println("font : " + getFont());
int fontHeight = getFontMetrics(getFont()).getHeight();

And here is the stackTrace :
false
font : null
java.lang.NullPointerException
at java.util.Hashtable.get(Unknown Source)
at java.awt.Component.getFontMetrics(Unknown Source)
at appli.MultiLineTable.getRowHeight(MultiLineTable.java:193)
...
Does Anybody has an idea why I can't set the font of my JTable.

Thanks.
Pierre.

Andrew Thompson

unread,
Aug 13, 2004, 4:25:29 AM8/13/04
to
On 13 Aug 2004 00:38:35 -0700, Pierre wrote:

> I'm trying to set font of a JTable but the method setFont(Font)
> doesn't seems to work in my case.

Your guess is wrong..

> Here is my code :
> setFont(Font.getFont("Arial"));

Try this and note the two results..
<sscce>
import java.awt.Font;

public class FontTest {
public static void main(String args[]) {
Font font1 = new Font("Arial", 20, 20),
font2 = Font.getFont("Arial");
System.out.println( "Font1 is: " + font1 );
System.out.println( "Font2 is: " + font2 );
}
}
</sscce>

HTH

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

Pierre

unread,
Aug 16, 2004, 3:04:39 AM8/16/04
to
OK, it seems I didn't read enough the javadoc...
Thanks for your help.
Pierre.
0 new messages