When i create a JCheckBox in my Swing application i leave some extra space after its label, so if the JCheckBox label is for example 100 pixels width, i make the JCheckBox 120 pixels for safety.
The problem as at runtime, it's not nice that a user can click on the empty space after the JCheckBox label and it can be actually clicked, like this :
I wonder if there is a way to resize the JCheckBox at runtime to exactly fit the text inside it, depending on the font type/size used ?
This seems fancy a bit, but i like to make things look perfect :)
Edit - More details :
I use FormLayout
, and I define the JCheckBox
like this :
CellConstraints con = new CellConstraints();
contentPane.add(checkBox1, con.xywh(3, 13, 10, 1));