Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JDesktopPane with JToolBar

Status
Not open for further replies.

jsulman

Programmer
Jun 14, 2001
85
US
Does anybody know what the trick is to add a JToolBar to a JDesktopPane? I am creating a MDI swing app and using JInternalFrames in a Layered Pane. I can get tool bars and menus in the JInternalFrames but only menus in the JDesktopPane.
Here is a snippit of code:

JDeskTopPane = new JDesktopPane(); //a specialized layered pane
setContentPane(desktop); // Set contnetPane to the desktop
// Create my tool bar....
..
..
desktop.add(jToolBar1, BorderLayout.CENTER);

When I try this nothing shows up. To test the code I did not left JFrames ContentPame to its default and then replaced desktop.add(jToolBar1, BorderLayout.CENTER); with
getContentPane.add(jToolBar1, BorderLayout.CENTER); and it worked.

Am I missing something?

Thanks in advance

Jeff Sulman
 
I think you have to add your toolbar to a new JPanel, then set this using setContentPane. Let us know if you need code examples... Alistair [monkey]
 
Alistair,
I tried doing this and it did acutally add the tool bar to the desk top. However, now I have the problem that every time I open an JInternalFrame on the desk top it puts it in the center of the layout and expands the frame so it fills the whole screen and it will not let me resize or move the it (actually it does but it just snaps back to its origional size as soon as I let go). It ignores my setSize() method. I tried other layout managers and they either do the same or something even worse. Do you have this problem? It would be good to see a few lines of code.


Thanks

Jeff Sulman
 
I got it figured out this weekend. I was setting desktop as the content pane instead of adding the desktop to the default layout manager of the contentpane. Works fine now. Added a status bar and a button bar.

Thanks for you help!!

Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top