class ColumnSelectionPanel extends JPanel {

    private final Map<ColumnSelectionModel, JCheckBox> checkBoxes;

    public ColumnSelectionPanel(ColumnSelectionModel[] columns) {
        checkBoxes = new HashMap<>();
        setLayout(new GridBagLayout());
        init(columns);
    }

    public static void showColumnSelectionPopup(ColumnSelectionModel[] columns, Component c) {
        JPopupMenu popup = new JPopupMenu();

        for (int col = 0; col < columns.length; col++) {
            final ColumnSelectionModel column = columns[col];
            final JCheckBoxMenuItem checkBox = new JCheckBoxMenuItem();
            checkBox.setText(column.getName());
            checkBox.setSelected(column.isSelected());
            checkBox.setEnabled(column.isEnabled());
            checkBox.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent evt) {
                    column.setSelected(checkBox.isSelected());
                }
            });
            popup.add(checkBox);
        }

        popup.show(c, 8, 8);
    }

    public static void showColumnSelectionDialog(ColumnSelectionModel[] columns, String dialogTitle) {<FILL_FUNCTION_BODY>}

    public void init(ColumnSelectionModel[] columns) {
        int i = 0;
        int j = 0;
        int width = 1;
        int rows = columns.length / width;

        for (int col = 0; col < columns.length; col++) {
            if (i >= rows) {
                i = 0;
                j++;
            }
            ColumnSelectionModel column = columns[col];
            JCheckBox checkBox = new JCheckBox();
            checkBox.setText(column.getName());
            checkBox.setSelected(column.isSelected());
            checkBox.setEnabled(column.isEnabled());

            GridBagConstraints gridBagConstraints = new GridBagConstraints();
            gridBagConstraints.gridx = j;
            gridBagConstraints.gridy = i + i;
            gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 12);
            gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
            gridBagConstraints.weightx = 1;
            add(checkBox, gridBagConstraints);
            checkBoxes.put(column, checkBox);
            i++;
        }
    }

    private void applyDialogChanges() {
        for (Iterator<ColumnSelectionModel> it = checkBoxes.keySet().iterator(); it.hasNext(); ) {
            ColumnSelectionModel columnModel = it.next();
            JCheckBox checkBox = checkBoxes.get(columnModel);
            columnModel.setSelected(checkBox.isSelected());
        }
    }

    public interface ColumnSelectionModel {

        boolean isEnabled();

        boolean isSelected();

        void setSelected(boolean selected);

        String getName();
    }
}

        ColumnSelectionPanel panel = new ColumnSelectionPanel(columns);
        int res = JOptionPane.showConfirmDialog(null, panel, dialogTitle, JOptionPane.OK_CANCEL_OPTION);
        if (res == JOptionPane.OK_OPTION) {
            panel.applyDialogChanges();
        }
    
<methods>public void <init>() ,public void <init>(java.awt.LayoutManager) ,public void <init>(boolean) ,public void <init>(java.awt.LayoutManager, boolean) ,public javax.accessibility.AccessibleContext getAccessibleContext() ,public javax.swing.plaf.PanelUI getUI() ,public java.lang.String getUIClassID() ,public void setUI(javax.swing.plaf.PanelUI) ,public void updateUI() <variables>private static final java.lang.String uiClassID