Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2006

Tip: Looking for answers? Try searching our database.

using JLayeredPane

Thread view: 
Monique Y. Mudama - 27 Feb 2006 18:36 GMT
Is it possible to successfully add it to another JComponent, or must
you set it as the contentPane of a JFrame?

Signature

monique

Vova Reznik - 27 Feb 2006 19:06 GMT
> Is it possible to successfully add it to another JComponent, or must
> you set it as the contentPane of a JFrame?

Must not.
http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html

"...Every Swing container that has a root pane — such as JFrame,
JApplet, JDialog, or JInternalFrame — automatically has a layered pane. ..."
Monique Y. Mudama - 27 Feb 2006 19:48 GMT
>> Is it possible to successfully add it to another JComponent, or must
>> you set it as the contentPane of a JFrame?
[quoted text clipped - 5 lines]
> JApplet, JDialog, or JInternalFrame — automatically has a layered
> pane. ..."

Thank you, but that wasn't really what I was trying to get at.  None
of the containers described in that quote are JComponents.

I don't want the entire JApplet to use a layered pane.  I want a
subsection, added to a JPanel, to be layered.

The tutorial you linked, which I have read (but possibly not in enough
detail), has example code that uses JFrame's setContentPane() method to
use a custom built JLayeredPane.  I want to know if I can do something
like:

JPanel panel = new JPanel();
JLayeredPane layers = new JLayeredPane();

// add stuff to JLayeredPane

panel.add(layers);

So far, it hasn't worked: the area that should contain the layers is
just grey/blank.

Here's some example code; the actual app for which I'd like this
functionality is pretty complicated.  But I think if I could get this
sample to work, I could also get the app to work:

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;

  public class LayeredPaneTest
  {

     public static void main (String[] args)
     {
        go();
           
        protected static void go()
        {
           JFrame frame = new JFrame();
           JLayeredPane pane = new JLayeredPane();
           pane.add(new JLabel("foo"), new Integer(0));
           pane.add(new JLabel("bar"), new Integer(1));
                   
           frame.getContentPane().add(pane);
           frame.pack();
           frame.setVisible(true);
        }
           
     }
  }

Signature

monique

Monique Y. Mudama - 27 Feb 2006 20:05 GMT
> Here's some example code; the actual app for which I'd like this
> functionality is pretty complicated.  But I think if I could get
> this sample to work, I could also get the app to work:

I figured it out.  I needed setBounds() on the component added to the
JLayeredPane.

Unfortunately, that doesn't seem like it's very helpful when the
components need to stretch ... I guess there's probably a way to set
up a listener to continuously redo the setBounds()?  But surely
there's a better way?

Signature

monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Vova Reznik - 27 Feb 2006 20:06 GMT
OK, no problem, just follow

> import javax.swing.JFrame;
> import javax.swing.JLabel;
[quoted text clipped - 11 lines]
>             JFrame frame = new JFrame();
>             JLayeredPane pane = new JLayeredPane();

        Component c = new JLabel("foo");

/*
* IMPORTANT size of your JLabel is 0x0
* :)
* That is why you cannot see it!!!
 */
        c.setSize(100, 20);

>             //pane.add(new JLabel("foo"), new Integer(0));

        pane.add(c, new Integer(0));

>             pane.add(new JLabel("bar"), new Integer(1));
>                    
>             frame.getContentPane().add(pane);

/*
 * Some components may need setVisible (JInternalFrame for example)
*/

>             frame.pack();
>             frame.setVisible(true);
>          }
>              
>       }
>    }


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.