JPanel buttonPanel = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.fill = GridBagConstraints.HORIZONTAL; bApply = new JButton("Apply"); bApply.addActionListener(this); bApply.setEnabled(false); buttonPanel.add(bApply); JButton bClose = new JButton("Close"); bClose.addActionListener(this); c.gridx = 1; buttonPanel.add(bClose); mainPanel.add(buttonPanel);
mainPanel.add(Box.createRigidArea(new Dimension(0, 5))); mainPanel.add(buttons);
    private void init() {        JTabbedPane tabs = new JTabbedPane(JTabbedPane.TOP);        tabs.add("Shape", createShapePanel());        tabs.add("Options", createOptionsPanel());        tabs.add("Custom", createCustomPanel());        JPanel mainPanel = new JPanel();        mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));        mainPanel.add(tabs);        JPanel buttonPanel = new JPanel(new GridBagLayout());        GridBagConstraints c = new GridBagConstraints();        c.gridx = 0; c.gridy = 0; c.weightx = 1;        c.fill = GridBagConstraints.HORIZONTAL;        bApply = new JButton("Apply");        bApply.addActionListener(this);        bApply.setEnabled(false);        buttonPanel.add(bApply);        JButton bClose = new JButton("Close");        bClose.addActionListener(this);        c.gridx = 1;        buttonPanel.add(bClose);        mainPanel.add(buttonPanel);        getContentPane().add(mainPanel);        getRootPane().setDefaultButton(bClose);    }