Hello All,

I am having trouble setting the rows in my JTable.

I want the user to be able to set how many rows there are in the table. ie.
When the use types in 30 in the text field I want the JTable rows to adjust and have 30 rows going downwards.

Could anyone please help me?
please look at my code in that I have so far.
Thanks
Lol

Code:
import javax.swing.*;
import javax.swing.table.TableModel;
import java.io.*;
import java.util.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.*;
import javax.swing.table.DefaultTableModel;

public class si1 extends javax.swing.JFrame implements ActionListener {
    JTextField name = new JTextField(15);
    JTextField name1 = new JTextField(15);
    public si1() {
        super("DataBase Loader");
        setSize(1025,740);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel pane = new JPanel();
        JPanel pane1 = new JPanel();
        JPanel pane2 = new JPanel();
        JPanel pane3 = new JPanel();
        JPanel pane4 = new JPanel();
        pane.setLayout(new GridLayout(20,1));
        pane1.setLayout(new BorderLayout());
        int j=10;
        String[][] data = new String[j][2];
        for (int k=0; k<j; k++){
           String[] row = {"",""};
           data[k] = row;
        }
        String[] columnNames = {"First Name", "Last Name"};
        final JTable perstab = new JTable();//(data, columnNames);
	DefaultTableModel  model2 = new DefaultTableModel(data, columnNames);
	perstab.setModel(model2); 
        perstab.setGridColor(Color.yellow);
        perstab.setPreferredScrollableViewportSize(new Dimension(500,500));
        JScrollPane scrollPane = new JScrollPane(perstab);
        pane1.add(new JPanel(), BorderLayout.EAST);
        JButton btn = new JButton("What are the names?");
        btn.addActionListener(this);
        btn.putClientProperty("DATABASE", perstab);
        pane1.add(new JPanel().add(btn), BorderLayout.SOUTH);
        pane2.add(name);
        pane3.add(name1);
        pane.add(pane2);
        pane.add(pane3);
        pane1.add(pane, BorderLayout.WEST);
        pane4.add(scrollPane);
        pane1.add(pane4, BorderLayout.CENTER);
        setContentPane(pane1);
	name1.addActionListener(new ActionListener() {
	public void actionPerformed(ActionEvent e) {
	System.out.println(perstab.getModel().getClass());
	((DefaultTableModel)perstab.getModel()).setColumnCount(Integer.parseInt(name1.getText()));
	}
	}
	);
	

        show();
    }
    public static void main(String[] args) {
        si1 frame = new si1();
        frame.setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
        JTable table = (JTable)((JButton)e.getSource()).getClientProperty("DATABASE");
        TableModel model = table.getModel();
        int count = model.getRowCount();
        String[] firstnames = new String[count];
        String[] lastnames = new String[count];
        for (int i=0; i < count; i++) { 
           firstnames[i] = (String)model.getValueAt(i, 0);
            System.out.println("first name at row " + i + ": " + firstnames[i]);
            lastnames[i] = (String)model.getValueAt(i, 1);
            System.out.println("lastname name at row " + i + ": " + lastnames[i]);
        }
    }
}