datebox popup position

584 views
Skip to first unread message

Stephen

unread,
Dec 4, 2009, 12:26:49 AM12/4/09
to Google Web Toolkit
Hi,

How do you position the datepicker popup for a DateBox ? Right now I
am just doing a

DateBox myDB = new DateBox();

and the datepicker appears below the textbox when you click on it. I
see that on the gwt showcase example their's is popping up ABOVE the
text box as seen here: http://gwt.google.com/samples/Showcase/Showcase.html#CwDatePicker

I would like it to pop out to the right, how is this accomplished. I
have googled every query I can think of and can't find anything on
this....


.... dare I Bing ?


- Stephen

Jim Douglas

unread,
Dec 4, 2009, 12:56:21 AM12/4/09
to Google Web Toolkit
If you play with it some more, you'll find that the date picker
appears relative to the edit box, which means below the edit box if
there's room, otherwise above it. If you'd like to impose different
positioning rules, the logical thing to do would be to override
showDatePicker(), but it's complicated by the fact that the PopupPanel
variable is private.

http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/user/datepicker/client/DateBox.html#showDatePicker()
http://google-web-toolkit.googlecode.com/svn/trunk/user/src/com/google/gwt/user/datepicker/client/DateBox.java

/**
* Parses the current date box's value and shows that date.
*/
public void showDatePicker() {
Date current = parseDate(false);
if (current == null) {
current = new Date();
}
picker.setCurrentMonth(current);
popup.showRelativeTo(this);

Jeppe Hansen

unread,
Oct 30, 2014, 8:27:55 AM10/30/14
to google-we...@googlegroups.com
Unbelievable that there is no nice way to specify where the popup should appear. 
Any way, I made a simple work around that I would like to share with you:


// This is a hack to have the popup shown above the text field.
private static void addPositionAdjustHandlers(DateBox dateBox) {
dateBox.getTextBox().addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
adjustPosition(dateBox);
}
});
dateBox.getTextBox().addFocusHandler(new FocusHandler() {
@Override
public void onFocus(FocusEvent event) {
adjustPosition(dateBox);
}
});
dateBox.getTextBox().addKeyDownHandler(new KeyDownHandler() {
@Override
public void onKeyDown(KeyDownEvent event) {
adjustPosition(dateBox);
}
});

}

private static void adjustPosition(DateBox dateBox) {
int top = - (dateBox.getDatePicker().getElement().getAbsoluteBottom() - 
dateBox.getDatePicker().getElement().getAbsoluteTop());
dateBox.getDatePicker().getElement().setAttribute("style", "visibility: visible; overflow: visible; position: absolute; left: 0px; top: "+ top +"px;");
}



/ Jeppe

Vassilis Virvilis

unread,
Oct 30, 2014, 9:51:48 AM10/30/14
to google-we...@googlegroups.com
I don't know if your popup is a PopupPanel or a DialogBox. Here are my observations anyway...

https://groups.google.com/forum/#!search/web$20toolkit$20virvilis$20dialogbox/google-web-toolkit/tZ79yCvgNuU/HeXX9eAGeJ4J

    Vassilis





/ Jeppe

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.



--
Vassilis Virvilis
Reply all
Reply to author
Forward
0 new messages