I have two JButton with the texts "Ok" and "Cancel". I use GridBagLayout to align them in JDialog . I set the anchor on GridBagConstraints.CENTER . Due to the difference in the number of characters in the "OK" and "Cancel" texts, the buttons have different sizes. How to align them correctly so that each of them has the same size. I tried the following but did not help.
okayButton.setSize(cancelButton.getSize());
source share