I am trying to create grab the gpahicConxtex of JComponent atr save it to a file, which works fine. Now I want to do this same thing on the JFrame.
The thing is that I don't want to show the JFrame to the user.
public static BufferedImage createImage(Object _component,
int imageType){
Component component=null;
if (_component instanceof JComponent) {
component = (JComponent) _component;
}else if(_component instanceof JFrame){
component = (JFrame) _component;
}
System.out.println(" Comp Type="+(_component instanceof JFrame));
System.out.println( component.getPreferredSize() );
Dimension componentSize = component.getPreferredSize();
component.setSize(componentSize); //Make sure these
//are the same
BufferedImage img = new BufferedImage(componentSize.width,
componentSize.height,
imageType);
Graphics2D grap = img.createGraphics();
grap.fillRect(0,0,img.getWidth(),img.getHeight());
component.paint(grap);
return img;
}
Greg
Thanks , thats exacly what I was thinking. I am using following code
Container content_frame = frame.getContentPane();
rootPanel = new JPanel();
content_frame.add( rootPanel );
Then every thing else gets added to the rootPane. The only draw back to this approach is that it will not let me capture complete JFrame, including title and window icons(min,max,close).
I haven't realized that I am in Reflections & Reference Objects Forum , sorry about that.
> Thanks , thats exacly what I was thinking. I am using
> following code
>
> > Container content_frame = frame.getContentPane();
> rootPanel = new JPanel();
> content_frame.add( rootPanel );
>
>
> Then every thing else gets added to the
> rootPane. The only draw back to this approach
> is that it will not let me capture complete JFrame,
> including title and window icons(min,max,close).
>
capture in what way? those attributes aren't related to any graphics context, they're just attributes of the JFrame. you can capture and serialize them as normal
>
>
> I haven't realized that I am in Reflections &
> Reference Objects Forum , sorry about that.
no worries