File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JButton with a pop up menu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JButton with a pop up menu" Watch "JButton with a pop up menu" New topic
Author

JButton with a pop up menu

Derrick Albers
Greenhorn

Joined: Nov 01, 2010
Posts: 20
I have a JButton that I want to add a menu to, I was using a mouseClicked and listening for 1 or 2 clicks, 2 bringing up the menu. The problem is that this button fires a single click to quickly and it is hard to get a double click in. So I create an arrow icon to memic a drop down button, on mousePressed the menu pops up just as it should, however if the user just wanted to use the button ( a single click ) they are not able to do so because the mouse pressed fires and ignores the release. How can I determine if the user has simple pressed the button or are they holding the button to get the menu?
Stanislav Lapitsky
Ranch Hand

Joined: Dec 01, 2009
Posts: 53
On press button start a timer with reasonable delay. In the timer action check pressed state. If the button still pressed show your popup. On release action stop the timer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JButton with a pop up menu