class JPopupButton extends JButton {

    private final ArrayList<JPopupButtonItem> items;
    private JPopupButtonItem selectedItem;
    private ChangeListener listener;

    public JPopupButton() {

        items = new ArrayList<>();
        addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                JPopupMenu menu = createPopup();
                menu.show(JPopupButton.this, 0, getHeight());
            }
        });
    }

    public JPopupMenu createPopup() {
        JPopupMenu menu = new JPopupMenu();
        for (final JPopupButtonItem item : items) {
            JRadioButtonMenuItem r = new JRadioButtonMenuItem(item.object.toString(), item.icon, item == selectedItem);
            r.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (item != selectedItem) {
                        selectedItem = item;
                        fireChangeEvent();
                    }
                }
            });
            menu.add(r);
        }
        return menu;
    }

    public void addItem(Object object, Icon icon) {
        items.add(new JPopupButtonItem(object, icon));
    }

    public Object getSelectedItem() {
        return selectedItem.object;
    }

    public void setSelectedItem(Object item) {<FILL_FUNCTION_BODY>}

    public void setChangeListener(ChangeListener changeListener) {
        listener = changeListener;
    }

    private void fireChangeEvent() {
        if (listener != null) {
            listener.stateChanged(new ChangeEvent(selectedItem.object));
        }
    }

    private class JPopupButtonItem {

        private final Object object;
        private final Icon icon;

        public JPopupButtonItem(Object object, Icon icon) {
            this.object = object;
            this.icon = icon;
        }
    }
}

        for (JPopupButtonItem i : items) {
            if (i.object == item) {
                selectedItem = i;
                return;
            }
        }
        throw new IllegalArgumentException("This elemen doesn't exist.");
    
<methods>public void <init>() ,public void <init>(javax.swing.Icon) ,public void <init>(java.lang.String) ,public void <init>(javax.swing.Action) ,public void <init>(java.lang.String, javax.swing.Icon) ,public javax.accessibility.AccessibleContext getAccessibleContext() ,public java.lang.String getUIClassID() ,public boolean isDefaultButton() ,public boolean isDefaultCapable() ,public void removeNotify() ,public void setDefaultCapable(boolean) ,public void updateUI() <variables>private static final java.lang.String uiClassID