Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_java thread: Re: joining two or more jtables...


Message #1 by "Kevin Mukhar" <kmukhar@e...> on Tue, 12 Feb 2002 20:45:44
If it is at all possible to combine two sets of data into a single table, 
it will involve creating a custom TableModel. You can find a lot of 
examples of custom TableModels here: 
http://www2.gol.com/users/tame/swing/examples/SwingExamples.html. Looking 
through the JTable examples, you might be able to adapt a couple of the 
examples to do what you want to do.

I've assumed that you are trying to display two sets of data in one 
JTable.  If what you really want is to display two separate JTables in the 
same Panel, then that is quite easy. Create a JPanel, set its layout 
manager to GridLayout, then add the two JTables. The code will look 
something like this:

        JFrame f = new JFrame();
        JPanel p = new JPanel();
        p.setLayout(new GridLayout(0,1));
        JTable t1 = new JTable(d, n);
        JTable t2 = new JTable(d, n);
        
        p.add(t1);
        p.add(t2);
        
        f.getContentPane().add(p, BorderLayout.CENTER);

> 2 jtables: table1 and table2....
> 
> table1:
> 
> |----------|----------|----------|----------|
> | col1     | col2     |  col3     | col4     |
> |----------|----------|----------|----------|
> |            |             |            |             |
>                 data.....
> 
> 
> 
> 
> table2:
> 
> |-------------|--------------|
> |   cola       |     colb      |
> |-------------|--------------|
> |                |                 |
>         data.........
> 
> 
> i would like to join these two tables so that the end result would be:
> 
> 
> |----------|------------|------------|-------------|
> |  col1    |    col2     |     col3    |   col4      |
> |----------|------------|------------|-------------|
> |            |               |                |                |
>                      data..........
> |             |              |                |                |
> |----------|------------|-------------|------------|
> |           cola           |           colb               |
> |-----------------------|--------------------------|
> |                             |                                |
>                       data..............
> |                              |                              |
> 
> 
> 
> 
> 
> anyone knows how to do this, or can point me to a tutorial or something?

  Return to Index