Unable to introduce Text in next line when using Header Checkbox

177 Views Asked by At

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.

1

There are 1 best solutions below

0
On

The Q&A How can I put a control in the JTableHeader of a JTable? includes several important caveats and shows an example using JToggleButton. In this case you want a two line JCheckBox without the complication of an enclosing JPanel.

You might look at implementing the Icon interface, as illustrated here for a TableCellRenderer. This would allow you to leverage the control offered by the component's horizontal and vertical alignment. For consistency, use the UI properties of the JCheckBox for the text, as shown in SelectAllHeader. I'd try rendering a JLabel in paintIcon (), but TextLayout, illustrated here, is an alternative way to get the correct metrics.