user3185198
user3185198

Reputation:

Adding JTable to a JScrollPane

I am trying to add a JTable to a JScrollPane. But I can't see the Table after doing this.

scrollpane.setBounds(100,50,800,400);
JTable table = new JTable(myTableModel(res));
scrollpane.add(table);

What's wrong with me?

Upvotes: 2

Views: 191

Answers (3)

neoprez
neoprez

Reputation: 349

Try this:

JTable table = new JTable(myTableModel(res));
JScrollPane scrollpane = new JScrollPane(table);
scrollpane.setBounds(100,50,800,400);

Upvotes: 0

RAJIL KV
RAJIL KV

Reputation: 399

Try this

scrollpane.setBounds(100,50,800,400);

JTable table = new JTable(myTableModel(res));

scrollpane.setViewporView(table);

Upvotes: -1

mKorbel
mKorbel

Reputation: 109813

scrollpane.add(table);

Upvotes: 6

Related Questions