I have a 2D array. The 2D array already contains the data. I need it to be filled in a JTable and display it. Below is my coding,
import arraypackage.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class form extends JFrame implements ActionListener,WindowListener
{
JButton b1; //processing takes place after button click
JTable table;
form()
{
setLayout(null);
b1 = new JButton("Process");
table = new JTable();
table.setBounds(350,200,100,300);
b1.setBounds(450,93,100,30);
add(b1);
b1.addActionListener(this);
setSize(1000,1000);
show();
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
data d = new data();
String resultfile[][]=d.dis();
for(int i=1;i<=resultfile.length;i++)
{
for(int j=1;j<=4;j++)
{
rows[i][j]=resultfile[i][j];
}
}
Object[] title = {"A","B","C","D"};
table = new JTable(rows, title);
add(table);
}
}
public void windowActivated(WindowEvent e1)
{
}
public void windowClosed(WindowEvent e2)
{
}
public void windowClosing(WindowEvent e3)
{
dispose();
}
public void windowDeactivated(WindowEvent e4)
{
}
public void windowDeiconified(WindowEvent e5)
{
}
public void windowIconified(WindowEvent e6)
{
}
public void windowOpened(WindowEvent e7)
{
}
public static void main(String s[])
{
form f = new form();
}
}
The Processing takes place but the table is not displayed. In the above coding, Arraypackage is my own package and it contains a class named data and it holds a method named dis. dis is a method which will return a 2D String array. It has been successfully returned and resultfile contains the correct 2D array values. The error lies while displaying the JTable i.e. the table is not displayed after clicking the button. Please, help me with this.