• 14
• 12
• 9
• 10
• 13

# Java, MDI, add components to JDesktopPane

This topic is 4496 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm making a MDI program. I can make the window, create child windows and everything is fine. But I had an idea of connecting a JTextArea to the JDesktopPane (to the empty background sort of) ... but this is proving difficult. I can't find any good examples out there. It seems I can only put an JInternalFrame to a JDesktopPane, but then again it is a window, and I can't get rid of the window look to it. I just want to display plain stuff on the background, as it was a plain window in itself. The only examples I have found is those who make MDI from scratch .... but that is just to much work ...

##### Share on other sites
Have you tried attaching a JPanel to the JDesktopPane? I don't have a Java environment set up right now, but usually for me whenever I need to attach components to anything, my first step is creating a JPanel to attach them to. Hope that helps :)

##### Share on other sites
I tried as you said ... like this

desktop = new JDesktopPane();add( desktop, BorderLayout.CENTER);JTextArea txt = new JTextArea( 10, 5 );txt.append( "Some text here - weeeeee");JPanel panel = new JPanel();panel.add( txt );panel.setVisible( true );desktop.add( txt );

Doesn't work. Everything else works by the way ... creating child windows etc ...

##### Share on other sites
My apologies, I didn't do my research properly. You are correct, it appears that the only JComponent you can attach to a JDesktopPane is a JInternalFrame. However, JInternalFrames are essentially designed to be JFrames for MDI applications that use JDesktopPanes. There's more info on using JInternalFrames here:

http://java.sun.com/docs/books/tutorial/uiswing/components/internalframe.html

Now, regular JFrames have a set method called setUndecorated(boolean) that determine whether or not a frame has window decorations (in general, not just provided by the look and feel). JInternalFrame unfortunately has no corresponding set method.

So here's my recommendation. First, I would try creating a JInternalFrame with the void constructor, passing it no arguments (thus non-resizable, no title string, icon, etc). See if it still gives you a border/title bar. If it does, you may want to look more into changing the look and feel of the JInternalFrame. Sorry I can't be of more help; my Eclipse setup is borked right now. Good luck!

Aviosity