-2

I am developing an java gui. It has TabedPane. I have added panel to tab. How to add jtable to panel which is in tab2;

mKorbel
  • 109,525
  • 20
  • 134
  • 319

2 Answers2

1

To get the compoenent at a particular index use getComponentAt (as suggested by Jonas Eicher in the comment.)

JPanel tabPanel = (JPanel) tabbedPane.getComponentAt(index);

Add your table to the panel like the following.

tabPanel.add(new JScrollPane(table));
Amarnath
  • 8,736
  • 10
  • 54
  • 81
0

Just create fields or local variables for your components, so you can reference them, i.e.:

JPanel panel = new JPanel();
JTable table = new JTable();

tabbedPane.insertTab("title", null, panel, null, 0);
panel.add(table);    
Jonas Eicher
  • 1,413
  • 12
  • 18