// menuParams: text, Runnable, ... // also: position := 'left/'center/'right static JButton jPopDownButton(S text, fO... menuParams) { ret jbutton((empty(text) ? "" : text + " ") + unicode_downPointingTriangle(), r { new JPopupMenu menu; int emptyCount = menu.getComponentCount(); S position = cast optPar_ignoreOddLength position(menuParams); // TODO: this fails when you include a separator without a following null fillJPopupMenu(menu, paramsWithout(menuParams, 'position)); if (menu.getComponentCount() != emptyCount) { JButton btn = heldInstance(JButton); int x = 0; if (eq(position, 'center)) x = (btn.getWidth()-getPreferredWidth(menu))/2; else if (eq(position, 'right)) x = btn.getWidth()-getPreferredWidth(menu); menu.show(btn, x, btn.getHeight()); } }); }