Button + menu in one component

Is it possible to create a button and a menu in one component?Simmiler to the Back button of the explorer - that contains a menu of the last X previous sites....thanks Liat
[200 byte] By [liat@bitband.coma] at [2007-9-29 20:00:44]
# 1

Yes.

Create a Jpanel, (directly from JButton may work) and implement javax.swing.MenuElement. If the button (in the JMenu) is not itself a menu you only have to over-ride MenuElement methods as so

public Component getComponent(){return this;}

public MenuElement[] getSubElements(){return new MenuElement[0];}

public void menuSelectionChanged(boolean isIncluded){}

public void processKeyEvent(KeyEvent event, MenuElement[] path, MenuSelectionManager manager){}

public void processMouseEvent(MouseEvent event, MenuElement[] path, MenuSelectionManager manager){}

Good luck. Bamkin

bamkin-ov-lestaa at 2007-7-16 0:15:17 > top of Java-index,Archived Forums,Swing...
# 2

Sorry, read the question wrong...

mouseEvent and keyEvent, (this could be done with a actonListener on the button) must alert a JMeuItems that they are to become visible, while they are visible menuStateChanged must return true. AND getSubElements must return an array of JMenuItems.

Bamkin

bamkin-ov-lestaa at 2007-7-16 0:15:17 > top of Java-index,Archived Forums,Swing...