I am working on a project which requires creating a number of JButtons. Each of these buttons will enclose different characters; a few of which containing words. The problem is I cannot seem to find out how I can set a JButton to resize based on its textual contents.
Is there a method which does this?
Thanks for any help.
JButton.getPreferredSize()will give you the size required to display the text and icon.The Button will automatically update it’s preferred size if you change the text/icon.
If the button is actually rendered in with its preferred size depends on the LayoutManager of its container.