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 / September 2005

Tip: Looking for answers? Try searching our database.

Help: How to use JWindow as Popup

Thread view: 
Mkhululi - 25 Sep 2005 12:53 GMT
Hi there,

I am developing a program & I wanted to design it with a screen like
the Mac OS (tiger?) desktop. That is menu (button bar) at the bottom of
the screen (the program's screen - Not the OS).

I thought I should use a JWindow to do it.

HOW I WOULD LIKE THE POPUP TO BEHAVE:

- Only appears when a user moves the mouse towards the bottom of the
screen.

- To disappear (hide) when the user clicks somewhere else on the screen
[when focus is lost(?)]
- To change its position relative to the program. That is, if the
program is resized etc...

I NEED YOUR HELP ON

The design issues I should take into consideration. I mean interfaces I
should implement etc...

Thanks in advance.

Yours,
Me

There
Roedy Green - 25 Sep 2005 22:04 GMT
>I am developing a program & I wanted to design it with a screen like
>the Mac OS (tiger?) desktop. That is menu (button bar) at the bottom of
[quoted text clipped - 16 lines]
>The design issues I should take into consideration. I mean interfaces I
>should implement etc...

That is quite a challenge.  What immediately comes to mind is an ugly
brute force solution.  You need to monitor mouse  moves/enters/exits
on the components that live where the bar will pop up. Then when the
mouse is in the critical region you make your bar visible and
revalidate, making the components resize to make room. When your mouse
does and exit from the bar, you revert to the old scheme.

see http://mindprod.com/jgloss/event11.html

A trickier implementation would paint top half of the container with
the normal components and the bottom slice with the bar. The
Components in the container would not change size, just be
overwritten.  you then have the problem of making sure mouse events
are delivered to the bar.

You might look at how CardLayout or JSplitPane is implemented.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Roedy Green - 25 Sep 2005 22:32 GMT
>A trickier implementation would paint top half of the container with
>the normal components and the bottom slice with the bar. The
>Components in the container would not change size, just be
>overwritten.  you then have the problem of making sure mouse events
>are delivered to the bar.

I have been thinking about your problem. It need not be nearly that
complicated.  All you need do is pop up a completely independent
window exactly the right size and position of the bar.

A JWindow is just like a JFrame except his comes with no canned
widgets to close etc it.

you create it, set its bounds, add children, validate, setvisible.
To get rid of it you call either hide or dispose depending on whether
you plan to pop it up again soon.

see http://mindprod.com/jgloss/jwindow.html

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Roedy Green - 25 Sep 2005 22:35 GMT
>I have been thinking about your problem. It need not be nearly that
>complicated.

This is a general rule. If you find yourself doing something bizarrely
complicated to solve something that seems like a simple problem,
others have probably run into the same trouble.  Likely there is a
tool for solving this if you look at your problem in a slightly
different way.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Roedy Green - 26 Sep 2005 03:45 GMT
>That is quite a challenge.  What immediately comes to mind is an ugly
>brute force solution.  You need to monitor mouse  moves/enters/exits
>on the components that live where the bar will pop up. Then when the
>mouse is in the critical region you make your bar visible and
>revalidate, making the components resize to make room. When your mouse
>does and exit from the bar, you revert to the old scheme.

I would experiment to see if the container still can see mouse moves
at its MouseListener even when there are components inside getting
them.  If so, it would be easier to monitor the entire container for
mouse moves with y > c.

If it it does not receive them, you would have to override at a lower
level.  See http://mindprod.com/gloss/event11.html for how.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Mkhululi - 27 Sep 2005 11:03 GMT
Hi,

After some researching on the problem I came across these classes

javax.swing.Popup

and

javax.swing.PopupFactory

And I thought I should analyse what they are doing. And I tried to
solve my problem using them but what came out in the end is not really
nice. Not functioning as a popup normally does.

If anyone of you knows some nice examples of Popup and PopupFactory
could you please give me a link or some guideline on how to use them.

Thanks in advance.

Yours,
Me
Roedy Green - 27 Sep 2005 23:40 GMT
>javax.swing.Popup
>
>and
>
>javax.swing.PopupFactory

Off the top of my head, the key pieces would be:

PopupFactory f = PopupFactory.getSharedInstance();

// A FancyPanel the thing you want to pop up.
panel = new FancyPanel();
Popup p = f.getPopup( parent, panel , x, y );
p.show();  // not setvisible (true );

Now some ActionListener on the FancyPanel or a timer or something else
will call p.hide() to dispose of the popup. and then set p= null to gc
it.

This is like a primitive JDialog or JOptionPane without any bells and
whistles.

Popups are not reusable.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



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.