I'm definitely not the best at explaining problem but let me try.
I have an applet with me. In a JTabel
I have one column as checkbox.
I want to have text added to it in the header only such that I have some text and than in the next line I have the checkbox.
Using headerRenderer
setText is not helping my cause as it appends the test to the checkbox instead of introducing a new line. Moreover I would like to avoid using JPanel
because I think it will create lot more problems for me.
Can anyone suggest how I can get this done?
If JPanel
is the only option can someone tell me how do I use that.
The Q&A How can I put a control in the
JTableHeader
of aJTable
? includes several important caveats and shows an example usingJToggleButton
. In this case you want a two lineJCheckBox
without the complication of an enclosingJPanel
.You might look at implementing the
Icon
interface, as illustrated here for aTableCellRenderer
. This would allow you to leverage the control offered by the component's horizontal and vertical alignment. For consistency, use the UI properties of theJCheckBox
for the text, as shown inSelectAllHeader
. I'd try rendering aJLabel
inpaintIcon ()
, butTextLayout
, illustrated here, is an alternative way to get the correct metrics.