简体   繁体   中英

JTable custom header renderer that looks like other headers with nimbus look and feel?

Any time I create a custom header renderer for a JTable it ends up not looking correct with the nimbus look and feel. The default table headers have a silvery gradient, custom renderers do not look that way. In the past I just avoided creating custom header renderers. Is it possible to copy the default look onto my new custom renderer? Basically I want to add a checkbox and have the area around it look like a normal column header, not just gray. I do know how to add the checkbox though and make it click-able. Thanks

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

Look at how Nimbus styles their Painter https://github.com/xsstomy/javacode/blob/master/javax/swing/plaf/nimbus/TableHeaderRendererPainter.java

Then you call on the component of your custom renderer

.setBackground(new MyTableHeaderRendererPainter());

Writing Painters is complicated. Unfortunately the Nimbus TableHeaderRendererPainter is not visible. Maybe you can use a Painter of a different lookandfeel to get an acceptable result.

使用tableHeader中的默认标题渲染器:

table.getTableHeader().getDefaultRenderer()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM