public JButton createButton(final int index, String text) {
        JButton b = new JButton();
        b.setText(text);
        b.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                switch (index) {
                    case 0:
                        if (!contextField.getText().isEmpty()) {
                            controller.addContext(contextField.getText().trim());
                        } else {
                            JOptionPane.showMessageDialog(null, "No context entered.");
                        }
                        break;
                    case 1:
                        if (contextList.getSelectedIndex() != -1) {
                            int result = JOptionPane.showConfirmDialog(null,
                                    "Are you sure you want to delete this context? It might be connected to an action."
                                    + "\n"
                                    + "\n"
                                    + "Actions with this context will be set to empty context.",
                                    "Are you sure?",
                                    JOptionPane.YES_NO_OPTION);
                            if (result == JOptionPane.OK_OPTION) {
                                controller.removeContext(contextList.getSelectedIndex());
                            }
                        } else {
                            JOptionPane.showMessageDialog(null, "No context selected.");
                        }
                        break;

                }
            }
        });
        if (index < 2 && index >= 0) {
            buttons[index] = b;
        }
        return b;
    }