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 / April 2006

Tip: Looking for answers? Try searching our database.

Moving a glass pane

Thread view: 
Mikl - 26 Apr 2006 08:15 GMT
Hi All,

I am trying to create a modal JInternalFrame.
There are the following code in the constructor

       JPanel glass = new JPanel();
       glass.setOpaque(false);

       setBounds(10, 10, 404, 313);
       glass.setSize(400,400);
       glass.setLocation(1,10)

       glass.add(this);

       glass.setLocation(1,10);
       rootPane.setGlassPane(glass);
       glass.setVisible(true);

I can see my modal window but it is always on the top and on the center
of the main Frame.
I was trying to set the size but it doesn't wark this way.
How can I locate, as I want, my JIF on this Glass layer?
Vova Reznik - 26 Apr 2006 14:37 GMT
> Hi All,
>
> I am trying to create a modal JInternalFrame.
> There are the following code in the constructor

of what? JInternalFrame?

>         JPanel glass = new JPanel();
>         glass.setOpaque(false);
[quoted text clipped - 7 lines]
>         glass.setLocation(1,10);
>         rootPane.setGlassPane(glass);

root pane of what? JInternalFrame? JFrame?

>         glass.setVisible(true);
>
> I can see my modal window but it is always on the top and on the center
> of the main Frame.
> I was trying to set the size but it doesn't wark this way.
> How can I locate, as I want, my JIF on this Glass layer?

Looks like you need to set glass pane for your JFrame, not for
JInternalFrame. Then you'll cover JFrame.
Mikl - 27 Apr 2006 06:18 GMT
Ok this is what I've got:

>From the main JFrame class (MDI application that was created by
NetBeans 5.0) I call a JIF:

       Update modal = new Update("Modal window", MainApp.this  );

       modal.setVisible(true);

       try {
           modal.setSelected(true);
       } catch (java.beans.PropertyVetoException e1) {}

This is some code of the Update class:

public class Update extends javax.swing.JInternalFrame {

   JPanel glass = new JPanel();
   MouseInputAdapter adapter = new MouseInputAdapter(){};

   public Update(String title, javax.swing.JFrame parent ) {

       super ( title );
       initComponents();

       glass.setOpaque(false);
       glass.addMouseListener(adapter);
       glass.addMouseMotionListener(adapter);

       glass.setBounds(20,20, 200, 200);
       glass.add(this);

       parent.getRootPane().setGlassPane( glass );

       glass.setVisible(true);

       System.out.println("InitGlass="+ glass.getLocation() + "
InitJIF="+ this.getLocation());
   }

This Update class size and all other properties are set through the
InitComponents().

When the window appreas, the printing line got the following results:
InitGlass=java.awt.Point[x=20,y=20] InitJIF=java.awt.Point[x=0,y=0]

I have a button on this internal frame and when I press it without
moving the window, then I got:
BtnGlass=java.awt.Point[x=5,y=5] BtnJIF=java.awt.Point[x=88,y=5]

If I move the window and press the button, the Point values are
different, but the glass location remains x=5, y=5.

What could be wrong? Why I can't set the proper location for the first
time?
Vova Reznik - 27 Apr 2006 15:01 GMT
> Ok this is what I've got:
>
[quoted text clipped - 24 lines]
>         glass.addMouseListener(adapter);
>         glass.addMouseMotionListener(adapter);

        /*
         * no needs to set bounds, glass pane
         * should cover whole JFrame (without title bar area)
         */
>         glass.setBounds(20,20, 200, 200);
        /*
         * If you need to show internal frame at specific
         * location then:
         */

          glass.setLayout(null);
          this.setLocation(10, 10);

>         glass.add(this);
>
>         parent.getRootPane().setGlassPane( glass );

          parent.setGlassPane(glass);

>         glass.setVisible(true);
>
[quoted text clipped - 17 lines]
> What could be wrong? Why I can't set the proper location for the first
> time?
Mikl - 27 Apr 2006 15:43 GMT
Thanks Vova, it works like a charm!


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.