Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need custom popup panel to display/hide like JComboBox popup  RSS feed

 
Diana McHenry
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I've build a custom Date picker utility that looks like a JComboBox, but is actually a JTextField next to a JButton, which when clicked displays a JPopupMenu. It's a long story, but extending JComboBox caused far more problems than it solved.

My problem is that I need the popup to hide whenever blank areas (unused portions) of the enclosing JPanel are clicked. It seems JPanel does not fire a focusGained event when it is clicked in this way. JComboBox instances hide their menus in this scenario, but I've not found the code in its class definition that makes this magic happen.

Here are the particulars of my code:

My JPopupMenu has a custom UI, which I extended from BasicPopupMenuUI:


Here is the code I use to display the popup:


I then have a FocusListener which closes the popup when it, or the adjoining JTextField lose focus:



I'd love to hear any advice/tips any of you might have.

Thanks very much,

Diana
 
Diana McHenry
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found a solution! It's not my favorite option, but it does seem to work

I added these two methods to my class:

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!