I'll start with what I want then go from there:
+------------------------------------------+
|[] jCheckBox jLabel |
+------------------------------------------+
Basically I would like to have a JCheckBox with 2 segments of text, 1 left aligned and 1 right aligned. I would like the entire box to be clickable and act exactly like a JCheckBox(As in if I press my mouse down it highlights the box ect.).
Now I have tried:
Using HTML inside the text box, with a table along the lines of:
<html><table width=100%><tr width=100%><td>Left Text</td><td align=right>Right Text</td></tr></table>. This produces[] Left TextRightTextwithout any visual alignment.Adding both the
JCheckBoxand theJLabelto a panel, however this would require me to implement all the mouse events and call the correct respective methods on theJCheckBox. I put this aside - however I am willing to reconsider if this is the only optionAdding the JLabel to the JCheckBox
- Firstly this caused the JCheckBox to decide to change the font, so that had to be 'adjusted'
- Secondly, the baselines were off by 1 or 2 pixels, This was fixed by implementing a LayoutManager that placed the
JLabelon the baseline. - Thirdly, the
JLabeloverlapped with theJCheckBoxtext so I ad to adjust my layout manager, however theJCheckBoxdid not give a correct result fromgetPreferedSize()(of[1,1]).
So, basically my question is: How should I implement this?