Display display = menuButton.getDisplay();
// Ensure that the popup remains within the bounds of the display
Point buttonLocation = menuButton.mapPointToAncestor(display, 0, 0);
Dimensions displaySize = display.getSize();
menuPopup.setPreferredSize(-1, -1);
Dimensions popupSize = menuPopup.getPreferredSize();
int popupWidth = Math.max(popupSize.width, menuButton.getWidth());
int popupHeight = popupSize.height;
int x = buttonLocation.x;
if (popupWidth > width