Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adding JPanel to JDesktopPane

332 views
Skip to first unread message

Ahmed Matar

unread,
Apr 25, 2002, 9:01:49 AM4/25/02
to
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


Maurice Naftalin

unread,
Apr 26, 2002, 4:24:54 AM4/26/02
to
Ahmed Matar wrote:

> 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).

> <snip>


>
> 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.

The mechanism that JDesktopPane uses to control its JInternalFrames isn't
compatible with a layout manager. You have to achieve the effect you want
in some other way. I'm guessing that you want a background on the JDP -
if so, you can either add a panel (or, easier, a JLabel with an icon) on the
lowest layer of the JDP, or you can override the paintComponent method
of the JDP itself to draw an image on it (that will resize the image
automatically
for you, whereas with a component you have to listen for resize events and
do it yourself).

Hope this helps
Maurice

0 new messages