Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Building a date picker - Popup, JWindow, JDialog, JComboBox, .... help!

843804Feb 1 2005 — edited Feb 2 2005
I'm trying to create a customised date selector, and I'm stumbling on the popup of a Component (subclass of JPanel).

My goal is to create the date-picker as an editible text field, to display and change the currently selected date in the application, and a button to popup a mini-calendar for graphical selection. Selecting a date from the popup or clicking anywhere outside the popup (so that the popup loses focus) should automatically close the popup (I don't want a "close" button). The popup should also appear over the button (or centered under the mouse). The popup and text field are bound together in a single object for easy inclusion in a number of different frames.

I've got the the text field and the calendar panel [1] working (more or less)... all I'm missing is the popup functionality. ie: 1: a container for a JPanel descendant. 2: position the container over the button that triggered its appearance and 3: hiding the container when a date is selected or focus is lost.

This functionality is similar to JComboBox, JPopupMenu etc, but none of the swing or awt components I've found so far (ie: JDialog, JComboBox, JPopupMenu, JWindow, Popup) allow me to pop up a JPanel over another component (the button) and then take control of focus/key/action events. The discussions I found on this forum hinted at solutions, but I didn't see any definitive "this works" messages.

I feel like I'm soooo close and yet.... what am I missing?

Thanks for any tips!

Steve

[1] The calendar panel is more like a jtable than a combo box or menu. It uses a calendar model and cell renderers to provide application-specific information. By changing the renderer, the same calendar panel class can be used as a full-blown editor, or as a mini-calendar overview. To the outside world it's just a single panel with specialized methods.

The structure of the panel (making the calendar naked and adding decorators as needed for buttons etc) was inspired by http://www.javaworld.com/javaworld/jw-07-2003/jw-0704-toolbox.html
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 2 2005
Added on Feb 1 2005
2 comments
503 views