JTable custom header renderer that looks like other nimbus effect headers?

Each time I create a custom header renderer for JTable, it does not look correct with the look and feel of nimbus. Table headers have a silver gradient by default; custom renderers don't look like this. I used to just avoid creating my own renderings of the headers. Can I copy the default image to my new custom renderer? Basically, I want to add a check box, and the area around it looks like a regular column heading, not just gray. I know how to add a checkbox and make it clickable. Thanks

+5
source share
2 answers

You can create MyTableHeaderRendererPainter extends AbstractRegionPainter (javax.swing.plaf.nimbus.AbstractRegionPainter).

See how Nimbus stylizes his artist https://github.com/xsstomy/javacode/blob/master/javax/swing/plaf/nimbus/TableHeaderRendererPainter.java

Then you call the component of your custom renderer

.setBackground(new MyTableHeaderRendererPainter());

It’s hard for artists to write. Unfortunately, Nimbus TableHeaderRendererPainter is not displayed. Maybe you can use Painter of a different style to get an acceptable result.

0
source

Use the default header renderer from your TableHeader:

table.getTableHeader().getDefaultRenderer()

-1
source

All Articles