Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JButton with a pop up menu  RSS feed

 
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?
 
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.
 
If you live in a cold climate and on the grid, incandescent light can use less energy than LED. Tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!