Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Jtable adding row dynamically

351 views
Skip to first unread message

Little Gal

unread,
Jul 28, 2000, 3:00:00 AM7/28/00
to
Hi all,
If i am using JTable, how can i add row while the applet is running???

Thanks!!!!

Hans Kamp

unread,
Jul 28, 2000, 3:00:00 AM7/28/00
to

"Little Gal" <sidn...@frontoffice.com.hk> schreef in bericht
news:39815654$1...@newsgate.hknet.com...

> Hi all,
> If i am using JTable, how can i add row while the applet is running???

For solving this problem I have written a little Java applet:

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;

public class AddRow extends JApplet
{
JButton button;
Container c;

// define a model which the table has to communicate with

DefaultTableModel dtm = new DefaultTableModel();

// define a table

JTable t;

// create as much objects as there are columns. There are four columns
(Name, Address, Zip Code and Place

Object rowData[] = new Object[4];

public void init()
{

// query the content pane
c = getContentPane();

// declare a table based on the Default Table Model
t = new JTable(dtm);

// place the table in the scroll pane and put the scroll pane in the
content pane of the applet

c.add(new JScrollPane(t));

// adding columns into the model whose effect is immediately visible
in the table

dtm.addColumn("Name");
dtm.addColumn("Address");
dtm.addColumn("Zip Code");
dtm.addColumn("Place");

// now I want to add rows (c.q. records) to my table

// adding my own address

rowData[0] = "Hans Kamp";
rowData[1] = "Wilhelminastraat 60";
rowData[2] = "7511 DP";
rowData[3] = "Enschede";
dtm.addRow(rowData);

// adding my father's address. I hope he won't mind me doing so :-)

rowData[0] = "Johan Kamp";
rowData[1] = "Katoenstraat 3";
rowData[2] = "7621 TC";
rowData[3] = "Borne";
dtm.addRow(rowData);
}
}

Good luck!


--

Hans Kamp (Win2000)
in...@hanskamp.com
www.hanskamp.com
ICQ=65694322


Little Gal

unread,
Jul 29, 2000, 3:00:00 AM7/29/00
to
I am using Java 1.1.8 and swing-1.03
and i also use the TableSorter and TableModel
such that i donno how to utilize your suggested solution
Are there any other alternatives???

Regards,
Sidney

Hans Kamp <hmk...@home.nl> wrote in message
news:mDdg5.4214$dr.1...@news1.zwoll1.ov.nl.home.com...

0 new messages