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.
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"
