convert JFrame to JComponent

Hi,I need to convert JFrame to JComponent , does anyone know a way of doing it or is it even possible.Thanks Greg.
[135 byte] By [gregbugaja] at [2007-11-26 15:57:39]
# 1
can't be done. JFrame isn't a JComponentwhat are you really trying to do?
georgemca at 2007-7-8 22:18:35 > top of Java-index,Core,Core APIs...
# 2

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

gregbugaja at 2007-7-8 22:18:35 > top of Java-index,Core,Core APIs...
# 3
remember that we don't actually add components to a JFrame, we add them to the contentPane of a JFrame, which is usually a JPanel, which is a JComponent. it's not really JComponent you're interested in, it's Container. which a JFrames contentPane always ishope this helps
georgemca at 2007-7-8 22:18:35 > top of Java-index,Core,Core APIs...
# 4
btw, this question really belongs in the swing forum
georgemca at 2007-7-8 22:18:35 > top of Java-index,Core,Core APIs...
# 5

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.

gregbugaja at 2007-7-8 22:18:35 > top of Java-index,Core,Core APIs...
# 6

> 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

georgemca at 2007-7-8 22:18:35 > top of Java-index,Core,Core APIs...