Hello Guys
I writing blog to add JTable in Jpanel. JTable is an component of the swing package in java technology and also it's a class, so we need to create instance and using add() method add the JTable in JPanel.
Here, add() method used for adding the components in swing container.
For better understanding see below example :
JPanel panel = new JPanel();// creating instance of JPanel
this.setContentPane(panel);// add panel in ContentPane
panel.setLayout(null);// Set null layout
String data[][] = {{"1.", "ABC"}, {"2.", "DEF"}, {"3.", "GHI" }};
// filling row and column data in JTable
String col[] = {"Sr. No", "Name"};
JTable table = new Jtable(data,col);
table.setBounds(100, 100, 100, 80);
panel.add(table);// add table in panel using add() method
setVisible(true);
setSize(300,300);
0 Comment(s)