• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need custom popup panel to display/hide like JComboBox popup

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
reply
    Bookmark Topic Watch Topic
  • New Topic