sclass JPopDownButton > JButton { S menuPosition = "left"; // or "center" or "right" *() { this(""); } *(S text) { super(joinNemptiesWithSpace(text, unicode_downPointingTriangle())); main addActionListener(this, r openMenu); } *(IVF1 *fillMenu) { this(); } selfType content(O... items) { onFillingMenu(menu -> fillJPopupMenu(menu, items)); this; } event fillingMenu(JPopupMenu menu); swappable void fillMenu(JPopupMenu menu) { fillingMenu(menu); } void openMenu { new JPopupMenu menu; int emptyCount = menu.getComponentCount(); fillMenu(menu); if (menu.getComponentCount() == emptyCount) ret; int x = 0; if (eq(menuPosition, "center")) x = (getWidth()-getPreferredWidth(menu))/2; else if (eq(menuPosition, "right")) x = getWidth()-getPreferredWidth(menu); menu.show(this, x, getHeight()); } visual this; }