File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Adding a JComponent to JDesktopPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adding a JComponent to JDesktopPane" Watch "Adding a JComponent to JDesktopPane" New topic

Adding a JComponent to JDesktopPane

Ahmed Matar

Joined: Mar 23, 2002
Posts: 6
I'm trying to add some components to a JDesktopPane in addition to some JInternalFrames such that the JInternalFrames will display in front of these components when they are not iconified. The problem is that JDesktopPane's layout manger is null and once you set it to any LayoutManager by calling setLayoutManager(...), then the JInternalFrames appear on the same layer as the other components in the JDesktopPane and will be aligned with them according to the chosen LayoutManager's policy (very weird looking). So I'm figuring that the only way to display a JPanel for example in the background is by specifically calling setBounds or setSize method on this JPanel. In this way the JInternalFrames will behave "normally". However the problem I am facing with this approach is that since I'm not using a LayoutManager, then this means that I If the JDesktopPane's parent is resized then the JPanel I have will not resize automatically because the LayoutMananager of the JDesktopPane is null. So The only solution I have though of is to have the listen for Component resizing events by having the Parent (JFrame) implement ComponentListener and listen for the the componentResized event and whenever the JFrame is resized I can resize the background JPanel to the intended size by calling setBounds on it inside this method. This approach works, but I have not found it to be reliable. Sometimes (I'm not sure which one occurs) either the resize event is not detected or the JPanel is not resized after the setBounds call, which results in some strange look. This problem occurs I would say 1/10 times when the JFrame is resized.
Does anybody have any idea on how to solve this problem?? ? Also if anybody knows how to use a LayoutManager with JDesktopPane with the requirement that the JInternalFrames associated with this JDesktopPane behave correctly, then please inform me how to do so.
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Look at the code in this post. It adds a JLabel with an Image to the background of a JDesktopPane, but you can do this with any JComponent.


Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: Adding a JComponent to JDesktopPane
It's not a secret anymore!