Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JButton with a pop up menu  RSS feed

 
Derrick Albers
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!