Use a panel with a CardLayout. Then create two buttons and add each button to the CardLayout. The size of the panel will now be the size of the largest button. So when you click on a button you will need to swap buttons.
Thanks. The real code has more than 1 button, using the card manager looks like a huge hassle. I solved the problem by calling setSize(), setPreferredSize(), and setMaximumSize(), all with the same arguments, in ActionPerformed. You have to call all 3, call any 1 or 2 and the button resizes.
If you really want to change the button's text (as opposed to managing two buttons) there are ways it can be done. Two come to mind:
1) Use a layout manager that doesn't respect preferred sizes. You could replace your BoxLayout with GridLayout, or use the NORTH or SOUTH regions of BorderLayout. (downside: This approach may stretch your button wider than you would like.)
2) Call myButton.setPreferredSize() sometime before frame.pack(). (downside: It can be difficult to choose a size that works well with all possible LnFs.) In this particular case, since you're starting with a longer word and changing to a shorter one, something like myButton.setPreferredSize(myButton.getPreferredSize()) might work. Or myButton.setPreferredSize(myButton.getSize()) inside an InvokeLater.