Need button with pop up menu

Hi all,I need to develop a button, which on click should show a pop up menu.. .Is there any way to accomplish this, with out any signs of adding JMenu in this button....Thanks in advancePradeep
[221 byte] By [pradeep@echa] at [2007-11-27 3:05:14]
# 1
[url http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html#popup]Bringing Up a Popup Menu[/url].
camickra at 2007-7-12 3:50:34 > top of Java-index,Desktop,Core GUI APIs...
# 2

public class MousePopupListener extends MouseAdapter {

private JComponent owner;

public MousePopupListener(JComponent owner) {

this.owner = owner;

}

public void mousePressed(MouseEvent e) {

checkPopup(e);

}

public void mouseClicked(MouseEvent e) {

checkPopup(e);

}

public void mouseReleased(MouseEvent e) {

checkPopup(e);

}

void checkPopup(MouseEvent e) {

if (e.isPopupTrigger()) {

JPopupMenu popup = new JPopupMenu();

// populate the popup menu with your menu items

popup.show(this.owner, e.getX(), e.getY());

}

}

}

Now, call myButton.addMouseListener(new MousePopupListener(myButton))

kirillga at 2007-7-12 3:50:34 > top of Java-index,Desktop,Core GUI APIs...
# 3
Thanks for ur help. its working really fine, Now i need another help.I need to differentiate b/w right and left mouse click on a button. it has to open 2 different menus for right and left click. Is der any possible solution?
pradeep@echa at 2007-7-12 3:50:34 > top of Java-index,Desktop,Core GUI APIs...
# 4

public class MousePopupListener extends MouseAdapter {

private JComponent owner;

public MousePopupListener(JComponent owner) {

this.owner = owner;

}

public void mousePressed(MouseEvent e) {

checkPopup(e);

}

public void mouseClicked(MouseEvent e) {

checkPopup(e);

}

public void mouseReleased(MouseEvent e) {

checkPopup(e);

}

void checkPopup(MouseEvent e) {

if (e.isPopupTrigger()) {

iif(e.getButton()==MouseEvent.BUTTON1){

JPopupMenu popup1 = new JPopupMenu();

popup1.show(this.owner, e.getX(), e.getY());

//left mouse click on the button

}

else if(e.getButton()==MouseEvent.BUTTON3){

JPopupMenu popup2=new JPopupMenu();

popup2.show(this.owner, e.getX(), e.getY());

//right mouse click on the button

}

}

}

}

GanHaitiana at 2007-7-12 3:50:34 > top of Java-index,Desktop,Core GUI APIs...
# 5
> I need to differentiate b/w right and left mouse click on a button.SwingUtiltities.isLeftMouseButton(...);
camickra at 2007-7-12 3:50:34 > top of Java-index,Desktop,Core GUI APIs...