Closed wyj3531 closed 2 years ago
DefaultTableModel defaultTableModel = new DefaultTableModel(data, columnNames); WebTable table = new WebTable(StyleId.of("bottom-table"), defaultTableModel); table.setRowHeight(30); JTableHeader tableHeader = table.getTableHeader(); /tableHeader.setOpaque(true); tableHeader.setBackground(new Color(255,0,0));/ tableHeader.setPreferredSize(new Dimension(1,30)); JScrollPane scrollPane = new JScrollPane(table, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.putClientProperty(StyleId.STYLE_PROPERTY, StyleId.scrollpaneTransparentButtonless);
There are two ways in which you can customize table header style -
Modify default table header style - this will modify header style for all tables. Table header is not yet fully customizable since it uses a specific TableHeaderPainter
painter, but you can still adjust colors it uses. Here is the default tableheader.xml
contents you can override:
<skin xmlns="http://weblookandfeel.com/XmlSkin">
<!-- Table header -->
<style type="tableheader">
<component>
<opaque>true</opaque>
<foreground>black</foreground>
</component>
<painter>
<headerHeight>22</headerHeight>
<topBgColor>226,226,226</topBgColor>
<bottomBgColor>201,201,201</bottomBgColor>
<gridColor>170,170,170</gridColor>
</painter>
<!-- Default table header cell renderer label -->
<style type="label" id="renderer" extends="shadow" padding="0,2,1,2">
<component>
<opaque>true</opaque>
<horizontalAlignment>0</horizontalAlignment>
</component>
</style>
</style>
2. Modify default table style or create a custom one. In that table style you can customize header style directly. Default table style reuses the header style from [`tableheader.xml`](https://github.com/mgarin/weblaf/blob/master/modules/ui/src/com/alee/skin/light/resources/tableheader.xml), but nothing stops you from adjusting it:
```xml
<!-- Table -->
<style type="table" id="custom">
<!-- Table header -->
<style type="tableheader" id="header">
<!-- Custom settings -->
</style>
</style>
First option will allow you to adjust all headers for all tables at once, second option will allow you to customize header only for the tables your table style will be applied to.
en. fixed it by option 2. thank you
there is some proble ?how i can change the Jtable header bg color and for color? i try to this do this but no effect: JTableHeader header = webTable.getTableHeader(); header.setBackground(Color.black); header.setForeground(Color.yellow);
and i try to another method and my custom header no effect bottom-table can change but header.why this header i custom no effect.