Can anyone teach me how to create a JTable

In my project, i would like to make a class extends JTable for which it can function like the excel one.
This means that the table can split into two parts.
Each of them have a standalone view and can let user to update the table.

Had some time to spare so a quick rough example.
Note this makes use of the TableModel created by JTable when passed an Object[][].
I'd recommend instead that you create your own TableModel and pass that to both JTables yourself.
import javax.swing.*;
import javax.swing.table.*;
public class SplitTableDemo extends JFrame
   public SplitTableDemo(String title) {
        super(title);
        // prepare data
        int cols = 26;
        int rows = 200;
        Object[][] data = new Object[rows][cols];
        for (int j=0; j<rows; j++) {
            for (int k=0; k<cols; k++) {
                data[j][k] = new String("");
        // prepare column names
        Object[] columnNames = new Object[cols];
        for (int m=0; m<cols; m++) {
            char c = (char) (65+m);   
            columnNames[m] = String.valueOf(c);
        // create first table view
        JTable upperTable = new JTable(data, columnNames);
        // create second table view with same model (obtained from first)
        TableModel tm = upperTable.getModel();
        JTable lowerTable = new JTable(tm);
        // put tables in ScrollPanes
        JScrollPane upperScroller = new JScrollPane(upperTable);
        JScrollPane lowerScroller = new JScrollPane(lowerTable);
        // display in split pane
        JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, upperScroller, lowerScroller);
        this.getContentPane().add(sp);
   public static void main (String[] args)
      SplitTableDemo splitTableDemo = new SplitTableDemo("Split Table Demo");
      splitTableDemo.pack();
      splitTableDemo.show();
}

Similar Messages

Maybe you are looking for

  • ORA-07445

    Hi All, I recenly installed Oracle 10g Release 2 on Windows 2003 Standrad Edition.. And getting an error in my alert log file... ORA-07445: exception encountered: core dump [ACCESS_VIOLATION] [unable_to_trans_pc] [PC:0x60518765] [ADDR:0x4] [UNABLE_TO

  • Please Help!  Can't open files

    Recently I have been unable to open pdf files to view.  Not sure what has changed but I have downloaded the adobe reader several times, open the file and get a message that says adobe is installed, open and running.  When I go to view a file, I get a

  • Error in approve the leave request in MSS

    Hello, i m new in ESS/MSS.. right now working on maintanance project...All configuration settings are done by other guy. - I m facing error in approving the leave request in MSS .. it open a error page as of no page found ... can any body tell me the

  • Using Intel Solaris 8 with 2 monitors

    We are developping an application under Solaris 8 Intel that will use 2 monitors. We have learn that Matrox and Colorgraphics provide twin head boards that, when driven by a XiGraphics driver, will manage the 2 monitors. Did anyone have this experien

  • Consuming HTTPS based external service

    Hello, I am trying to generate consumer service proxy, for a HTTPS based service within the same organization, but I am trouble generating the proxy. Below is the error from task bar. *Exception occurred in communication framework:Error in HTTP Frame