🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
5 messages
5 total messages Started by Ted Byers Wed, 24 Mar 2004 20:53
How do I get at the root pane of JApplet and it's members?
#1092
Author: Ted Byers
Date: Wed, 24 Mar 2004 20:53
48 lines
2868 bytes
 I have a book on JFV/Swing and it says:

"Swing containers such as JApplet, JFrame, JWindow, JDialog, and
JInternalFrame delegate their duties to the root pane that is represented by
the class JRootPane" and "Because a root pane is made up of a content pane,
layered pane, glass pane and menubar, contents must be added to one of these
root pane members, rather than to the root pane.  You can get a reference to
the underlying root pane of a container by using the method getRootPane();"

It is my understanding that I can control wich Swing object is displayed on
top of the others, when there ae overlapping controls, by using the
different panes in the root pane, and also that the glass pane is
specifically for the sort of thing I have been trying to do, in terms of
having an invisible JLabel over top a visible JLabel which has an image.

My problem, at present, is that JBuilder9 doesn't seem to know about the
root pane and its data members, or about the functions rquired to access
them.

I am assuming that I am having trouble withmy mouse cursor is that for some
reason the invisible JLable is underneath the visible one.

The primary problem I am tying to solve is that, of the mouse events for
which I have created handlers, only the click event seems to be called.
Here is the relevant code:

  void jLabel2_mousePressed(MouseEvent e) {
    showStatus("HotSpotImageTest applet, component jLabel2: mousePressed");
  }

  void jLabel2_mouseEntered(MouseEvent e) {
    jLabel2.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  }

  void jLabel2_mouseExited(MouseEvent e) {
    jLabel2.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  }

jLabel2 is the invisible object, and the mouse_pressed event is called but
there is no evidence that the Mouse_Entered and Mouse_Exited events are
being called.  If they are, then the single statement in each has failed
silently.

Any ideas?

Thanks,

Ted
Re: How do I get at the root pane of JApplet and it's members?
#1099
Author: John McGrath [TeamB]
Date: Thu, 25 Mar 2004 23:09
29 lines
2072 bytes
On 3/24/2004 at 3:53:48 PM, Ted Byers wrote:

> My problem, at present, is that JBuilder9 doesn't seem to know about
> the root pane and its data members, or about the functions rquired to
> access them.

JBuilder's UI Designer works with the content pane, which is where most
components usually go in a Swing UI.  The root pane is generally not
used to lay out the GUI.  Instead, it is usually used for programmatic
manipulation of the GUI, such as with drag & drop, popup menus, etc.

Instead of messing with the root pane and layered pane, just place the
two labels together in a JPanel and place that in the content pane.  It
should work pretty much the same as what you have been doing, except
that the default for the layout manager will be different.

> I am assuming that I am having trouble with my mouse cursor is that
> for some reason the invisible JLabel is underneath the visible one.

That will do it.  If the JLabel is obscured, the cursor will not work.

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: How do I get at the root pane of JApplet and it's members?
#1102
Author: Ted Byers
Date: Fri, 26 Mar 2004 15:55
19 lines
1832 bytes
Thanks John.  It is all working now.

I am curious, though. Please consider the following lines of code:

    getContentPane().add(jLabel2, new XYConstraints(277, 108, 94, 65));
    getContentPane().add(jLabel1, new XYConstraints(17, 23, 753, 548));

I noticed that each time I put one or the other to the back, the order of
these statements gets changed when I look at the source after making the
change.  This is the sequence I needed to get everything to work (jLabel2 is
the invisible label and jLabel1 holds the picture).  Is it described
somewhere that the order in which components are added to a pane determines
their Z-order, and that the last component added will be behind the first?
None of the references I have used describe this (in fact one says that if I
want to control Z-order, I need to use the layered pane).

Thanks again

Ted
Re: How do I get at the root pane of JApplet and it's members?
#1101
Author: Ted Byers
Date: Fri, 26 Mar 2004 16:13
19 lines
1832 bytes
Thanks John.  It is all working now.

I am curious, though. Please consider the following lines of code:

    getContentPane().add(jLabel2, new XYConstraints(277, 108, 94, 65));
    getContentPane().add(jLabel1, new XYConstraints(17, 23, 753, 548));

I noticed that each time I put one or the other to the back, the order of
these statements gets changed when I look at the source after making the
change.  This is the sequence I needed to get everything to work (jLabel2 is
the invisible label and jLabel1 holds the picture).  Is it described
somewhere that the order in which components are added to a pane determines
their Z-order, and that the last component added will be behind the first?
None of the references I have used describe this (in fact one says that if I
want to control Z-order, I need to use the layered pane).

Thanks again

Ted
Re: How do I get at the root pane of JApplet and it's members?
#1106
Author: John McGrath [TeamB]
Date: Sat, 27 Mar 2004 10:40
37 lines
2473 bytes
On 3/26/2004 at 10:55:08 AM, Ted Byers wrote:

> I noticed that each time I put one or the other to the back, 
> the order of these statements gets changed when I look at the
> source after making the change.

Yes, the z-order is controlled by the order that the child components
are added to a Container.

> Is it described somewhere that the order in which components
> are added to a pane determines their Z-order, and that the last
> component added will be behind the first?  None of the references
> I have used describe this (in fact one says that if I want to
> control Z-order, I need to use the layered pane).

My first reaction to this was "sure, that should be *easy* to find",
but that turns out not to be the case.  It seems that the Java specs do
not say that this is so.

But people needed to be able to control the z-order, and a quick look
at the code in package "java.awt" shows that it is controlled by the
order in which the components are added.  Without any other documented
way to control the z-order (JLayeredPane did not yet exist), people
adopted this one, and it is now a de-facto way to do things.

Interestingly, JDK 1.5 will add new methods to the Container class that
allow you to control the z-order without removing components and adding
them again.

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads