Skip to Main Content

Re-sizing JButtons

843807Jun 9 2010 — edited Jun 9 2010
Having some problems with my JDialog Box. I like the size of the JDialog Box and the JTextArea, but I don't want the JButton's so big. Is there any way to re-size them. I have tried the setPreferredSize method, but it doesn't do anything. I am using GridBoxLayout.
public class CustomDialog extends JDialog implements ActionListener {
       
        private JPanel panel1 = null;
        private JPanel panel2 = null;
        private JPanel mainPanel = null;
        private JTextArea txtDatabaseSettings = null;
        private JButton cmdSave = null;
        private JButton cmdCancel = null;
    
        private boolean answer = false;
        
        public boolean getAnswer() { return answer; }

    public CustomDialog(JFrame frame, boolean modal, String myMessage) {
        super(frame, modal);

        txtDatabaseSettings = new JTextArea();
                
        cmdSave = new JButton("Save");
        cmdSave.setHorizontalAlignment(SwingConstants.CENTER);
        cmdSave.addActionListener(this);
        
        cmdCancel = new JButton("Cancel");
        cmdCancel.setHorizontalAlignment(SwingConstants.CENTER);
        cmdCancel.addActionListener(this);
          
        panel1 = new JPanel();
        panel1.setLayout(new GridLayout(1, 1));
        panel1.add(new JScrollPane(txtDatabaseSettings));
        
        panel2 = new JPanel();
        panel2.setLayout(new GridLayout(1, 2));
        panel2.add(cmdSave);
        panel2.add(cmdCancel);
        
        mainPanel = new JPanel();
        mainPanel.setLayout(new GridLayout(2, 1));
        mainPanel.setPreferredSize(new Dimension(350, 150));
        getContentPane().add(mainPanel);
        
        mainPanel.add(panel1);
        mainPanel.add(panel2);
     
        setTitle(myMessage);
        pack();
        setLocationRelativeTo(frame);
        setVisible(true);
    }
Any help would be appreciated.

Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked due to inactivity on Jul 7 2010
Added on Jun 9 2010
1 comment
422 views