How to show put JTable in a JScrollPane ?

I want to make my JTable, so it can has scrollbar (horizontal and vertical).

I have tried :

SpringLayout layout =new SpringLayout();

//==========================================================

Table_Data =new JTable(sData, sHeader);

Table_Data.setPreferredScrollableViewportSize(new Dimension(300, 100));

ScrollPane_Table =new JScrollPane(Table_Data);

//==========================================================

Panel_Data =new JPanel(layout);

Panel_Data.setPreferredSize(new Dimension(300,100));

Panel_Data.setBorder(BorderFactory.createLoweredBevelBorder());

Panel_Data.add(ScrollPane_Table);

//==========================================================

but still, the JTable doesn't have any scrollbar.

2ndly, how to make the JTable so it can auto adjust for the column width ? Because, my some of my JTable header show "abc..." and I have to adjust it manually 1 by 1.

Thank you

[1277 byte] By [Thunder_Blasta] at [2007-11-26 19:34:38]
# 1

Try this out

JTable table=new JTable();

table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;

int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;

JScrollPane jsp=new JScrollPane(table,v,h);

Thank you

jofin123a at 2007-7-9 22:08:34 > top of Java-index,Desktop,Core GUI APIs...
# 2

// These are the defaults so they are not needed.

//int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;

//int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;

JScrollPane jsp=new JScrollPane(table);

camickra at 2007-7-9 22:08:34 > top of Java-index,Desktop,Core GUI APIs...