• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Adding a JComponent to JDesktopPane

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Ahmed
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

-Nate
 
reply
    Bookmark Topic Watch Topic
  • New Topic