简体   繁体   中英

Background of background JTable header color

You can see on the following picture a part of my application. Basically a JFrame containing, between other things : a JTable within a JScrollPane .

I set the background color on both elements (see A) but where can I set the color on the arrow B ?

问题说明

Declared as follow :

public class CXPanel extends JPanel{ private JTablet_ao = new JTable(ViewsModelService.getCXTableModel(0));

public CXPanel() {
    GridBagConstraints c = new GridBagConstraints();
    (...)
    this.add(new CXSubPanel(), c);
}


public class CXSubPanel extends GamePanel {
    public CXSubPanel() {
        super(new GridLayout(3, 0, 0, 0));

        TableScrollPane sc_ao = new TableScrollPane();

        (... adding JTable to scrollpane ect...)

        this.add(sc_ao);
    }
}

}

The back ground color is set for each panel, scrollpane (and its viewport ) cell and header renderer of the table, example of header renderer :

public class CXHeaderRenderer extends JLabel implements TableCellRenderer {

        public CXHeaderRenderer() {
            this.setFont(ViewsPreferences.CX_HEADER_FONT);
            this.setForeground(ViewsPreferences.CX_HEADER_COLOR);
            this.setBackground(ViewsPreferences.CX_HEADER_BACKGROUND);
            this.setOpaque(true);
            this.setBorder(null);
            this.setHorizontalAlignment( JLabel.CENTER );
            this.setPreferredSize(new Dimension(ViewsPreferences.P_HEADER_WIDTH, ViewsPreferences.P_HEADER_HEIGHT));
        }

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            setText(value.toString());
            return this;
        }

    }

Aswer found (partially on this post ) :

table.getTableHeader().setBackground(myColor);
scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, dummyPanel);

Learn more about JScrollPane corners here , good thing to know : each JTable contains a JScrollPane .

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