Adding border around jtable

I have a jtable inside a gridbaglayout and want to put title border around the table and the table's header. Does anyone know how to do this?

panel.add(table.getTableHeader(), new GridBagConstraints(0,4,3,1,0,0,anchor,fill,new Insets(0,3,0,3),0,0));

panel.add(table, new GridBagConstraints(0,5,3,2,10,0,anchor,fill,new Insets(0,3,0,3),0,0));

table.setBorder(BorderFactory.createTitledBorder("Test Table"));

[446 byte] By [t503229] at [2007-9-26 1:48:04]
# 1

Create a JPanel(1) with a BorderLayout, add your JTable to it, and add this JPanel(1) to your Original JPanel(2). Then setBorder on the JPanel(1).

ex :

JPanel tablePanel=new JPanel(new BorderLayout());

tablePanel.add(jtable,"Center");

tablePanel.setBorder(BorderFactory.createTitledBorder("title"));

panel.add(tablePanel).

Hope it works.

Cedric

baiker at 2007-6-29 2:47:53 > top of Java-index,Archived Forums,Swing...