How to remove the Header Columns border

Asked

Viewed 97 times

0

I can’t seem to remove the white edge of the header of jTable

public static JTable CMtable(String[] colunas, int width, int height) {
    TableColumn coluna;
    JTable tbl = new JTable();
    tbl.setBounds(0,0,width,height);
    for (int i = 0; i < colunas.length; i++) {
        coluna = new TableColumn(i);
        coluna.setHeaderValue(colunas[i]);
        tbl.addColumn(coluna);
    }
    tbl.getTableHeader().getColumnModel().getColumn(0).setPreferredWidth(tbl.getWidth()*1/10);
    tbl.getTableHeader().getColumnModel().getColumn(1).setPreferredWidth(tbl.getWidth()*5/10);
    tbl.getTableHeader().getColumnModel().getColumn(2).setPreferredWidth(tbl.getWidth()*4/10);
    tbl.getTableHeader().setReorderingAllowed(false);
    tbl.getTableHeader().setResizingAllowed(false);
    tbl.setRowSelectionAllowed(false);
    tbl.setShowHorizontalLines(false);
    tbl.setShowVerticalLines(false); 

    tbl.setFont(new Font("Tahoma", 1, 14));
    tbl.setBackground(BdoColor.CINZA);
    tbl.getTableHeader().setFont(new Font("Tahoma", 1, 14));
    tbl.getTableHeader().setOpaque(false);
    tbl.getTableHeader().setForeground(Color.WHITE);
    tbl.getTableHeader().setBackground(BdoColor.CINZA);
    tbl.setAlignmentX(SwingConstants.CENTER);
    tbl.getTableHeader().setAlignmentY(SwingConstants.CENTER);
    tbl.setRowHeight(25, 1);
    tbl.setBackground(BdoColor.CINZA);

    return tbl;
}

The result after executing is as follows: inserir a descrição da imagem aqui

Just that I wish it didn’t have white edges, I tried to mess with setBorder but I didn’t get results.

I wait answer! , any study tip would be welcome! Thanks

1 answer

0

Import:

import javax.swing.BorderFactory

and try:

tbl.setBorder(BorderFactory.createLineBorder(Color.GRAY,1));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.