user7729338
user7729338

Reputation:

Need to add header on this table

I am trying to fetch data from SQlite DB and show it in JTable - but header not appear.

This my code:

JPanel panel =new JPanel();
panel.setLayout(null);
panel.setSize(5,5);

JTable tabel_1=new JTable();
tabel_1.setSelectionBackground(new java.awt.Color(0, 153, 51));

JTableHeader header=tabel_1.getTableHeader();
header.setBackground(Color.BLACK);

DefaultTableModel tableModel =(DefaultTableModel) DbUtils.resultSetToTableModel(rs);

tableModel.setColumnIdentifiers(headers);

tabel_1.setModel(tableModel);
frame.add(panel);

frame.add(tabel_1);

and this is result:

enter image description here

Upvotes: 1

Views: 29

Answers (1)

Abdelhak
Abdelhak

Reputation: 8387

Try to add JScrollPane in this part of code to your code like this:

  JTable tabel_1 =new JTable();
  tabel_1.setSelectionBackground(new java.awt.Color(0, 153, 51));
  JScrollPane tableScroll = new JScrollPane(tabel_1);

  frame.add(tableScroll);

Upvotes: 1

Related Questions