Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-15-2008, 08:24 PM
undertow's Avatar
Member
 
Join Date: Jan 2008
Location: Colorado USA
Posts: 12
undertow is on a distinguished road
Send a message via AIM to undertow Send a message via Skype™ to undertow
JPopupMenu falls behind window
hello, i seem to be having some trouble here. I am writing a little class that is a popupSlider widget. The class extends JLabel so the user would treat this component like a label. When the label is left clicked on a jpopupMenu with a slider in it appears. This works all well and good except the second i click on the slider, i still have control of the slider (i can drag it up and down), the popup menu then disappears behind the rest of the window. I'm thinking i am missing something when processing the click event or the release events.

(yea there is probably some ugly code here, but it is in development, i want to get the thing working then clean up the code.)

couple things to note:
'popup' is a JPopupMenu object with a JSlider simply 'add()'ed to it
Code:
public void mouseClicked(MouseEvent e) { System.out.println("clicked " + e.getSource().getClass() ); if(e.getButton() == MouseEvent.BUTTON1) { Point pos = getMousePosition(); pos.x += getLocationOnScreen().x; pos.y += getLocationOnScreen().y; popup.setLocation(pos); popup.setVisible(true); } } public void mouseReleased(MouseEvent e) { System.out.println("released " + e.getSource().getClass() ); if( (e.getButton() == MouseEvent.BUTTON1) && (e.getSource().getClass() == JSlider.class) ) { System.out.println("mouse released on slider"); popup.setVisible(false); } }
any help would be appreciated.
-Undertow
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-16-2008, 03:27 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,015
hardwired is on a distinguished road
the popup menu then disappears behind the rest of the window
Sounds like the "rest of the window" is or contains AWT/heavyweight components. Heavyweight components are always rendered above/on_top_of/in_the_way_of lightweight components. See Mixing heavy and light components for discussion.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-16-2008, 07:01 PM
undertow's Avatar
Member
 
Join Date: Jan 2008
Location: Colorado USA
Posts: 12
undertow is on a distinguished road
Send a message via AIM to undertow Send a message via Skype™ to undertow
Strange, apparently you cant have a JPopupMenu appear on top of a JFrame. Doesn't make a lot of sense to me. The thing appears when i click but as soon as i click to drag the slider the popup goes behind the JFrame. guess i am SOL. strange though, i've seen a package out there that is just this thing i am trying to do (i just don't want to pay for it). so i am assuming it is possible...
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-16-2008, 11:45 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,015
hardwired is on a distinguished road
cant have a JPopupMenu appear on top of a JFrame
Can you add the popup to a lightweight child (of the frame) component or perhaps the JRootPane of the JFrame?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-17-2008, 11:20 PM
undertow's Avatar
Member
 
Join Date: Jan 2008
Location: Colorado USA
Posts: 12
undertow is on a distinguished road
Send a message via AIM to undertow Send a message via Skype™ to undertow
PopupSlider solved.
Looks like YES you can have a JPopupMenu appear on top of a JFrame or a JPanel etc. etc. Looks like the key is implementing the MenuElement interface.

Code:
public class PopupSlider extends JSlider implements MenuElement { private JPopupMenu menu; public PopupSlider() { menu = new JPopupMenu(); setMajorTickSpacing(10); setMinorTickSpacing(5); setPaintLabels(false); setPaintTicks(true); setValue(0); setPaintTrack(true); setInverted(false); setOrientation(JSlider.VERTICAL); setSize(getPreferredSize()); addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { setVisible(false); } }); menu.add(this); } public void setLocation(int x, int y) { menu.setLocation(x,y); } public void setVisible(boolean v) { menu.setVisible(v); } public boolean isMenuVisible() { return menu.isVisible(); } public void processMouseEvent(MouseEvent e, MenuElement path[], MenuSelectionManager manager) { } public void processKeyEvent(KeyEvent e, MenuElement path[], MenuSelectionManager manager) { } public void menuSelectionChanged(boolean isIncluded) { } public MenuElement[] getSubElements() { return new MenuElement[0]; } public Component getComponent() { return this; } }
Using this class one could say; create a JLabel somewhere and add a mouse listener to it and call PopupSlider.setVisible() to make it appear. If you want to try something, first try it without modification and see that the slider stays ontop while you are working with it. Then go to the class and comment out the "implements MenuElement" and run again. This time you will see that the slider falls behind the window as soon as you start to use it.

So if anyone wants a nice little popup slider they can use and modify this class instead of paying the $15 or $20 for the JPopupSlider on the web.

Also if anyone cares, you could use a JDialog that is undecorated instead of a JPopupMenu to get cool bonuses like "always on top"


Last edited by undertow : 01-22-2008 at 05:30 AM. Reason: add a comment about interface implmentation
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
refresh a different window marceldupont AWT / Swing 3 03-22-2008 03:44 AM
disable parent window ismailsaleh AWT / Swing 1 01-08-2008 12:15 AM
drawing window BlitzA Advanced Java 0 12-30-2007 06:39 PM
drawing window BlitzA New To Java 0 12-30-2007 05:45 PM
dynamising the height of a JPopupMenu iimasd AWT / Swing 6 11-21-2007 11:01 AM


All times are GMT +3. The time now is 06:43 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org