Missing Graphics in JComponent or JPanel
From: ThomasH (henrymot_at_any.net)
Date: 11/30/04
- Next message: JS: "Re: Problems making a Graph"
- Previous message: IchBin: "Re: Problems making a Graph"
- Next in thread: A. Bolmarcich: "Re: Missing Graphics in JComponent or JPanel"
- Reply: A. Bolmarcich: "Re: Missing Graphics in JComponent or JPanel"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 29 Nov 2004 15:04:29 -0800
Hi,
I face a strange problem, which bugged me already back than with
AWT, Swing seems to have the same issue:
I extend JPanel and in the constructor I try to calculate
its preferred size. This size is related to size of used
fonts. Thus I do:
Font f;
FontMetrics=fm;
construct()
{
f=new Font(something);
setFont(f);
Graphics g=getGraphics();
if (g==null) {
System.out.print("No graphics in contr!!");
// add ad hoc values to dimension
} else {
fm=g.getFontMetrics()
// perf Form calculations
}
}
Now later I can (or rather must) obtain fm and calculate
the values in the paintComponent();
getGraphics() returns null silently, no exception is
being thrown. Browsing through the Swing information
'booklets,' such as Geary 1200 pages, or the Manning
Swing 2nd edition 1000 pages yields no help.
What do I do wrong? :-)
Thomas
- Next message: JS: "Re: Problems making a Graph"
- Previous message: IchBin: "Re: Problems making a Graph"
- Next in thread: A. Bolmarcich: "Re: Missing Graphics in JComponent or JPanel"
- Reply: A. Bolmarcich: "Re: Missing Graphics in JComponent or JPanel"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|