简体   繁体   English

JTable自定义标题渲染器,看起来像其他具有灵气的外观和感觉?

[英]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. 每当我为JTable创建自定义标题渲染器时,它最终看起来都不正确,具有灵气的外观和感觉。 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). 您可以创建一个MyTableHeaderRendererPainter扩展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 看看Nimbus如何设计他们的画家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. 不幸的是,Nimbus TableHeaderRendererPainter不可见。 Maybe you can use a Painter of a different lookandfeel to get an acceptable result. 也许你可以使用不同外观的画家来获得可接受的结果。

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

table.getTableHeader().getDefaultRenderer()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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