Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Didn't help much on the table stuff

 
maliny ramu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks dhwani mathur for your kindness reply.
Could you provide me with an example. My table is dynamic and insert new row is done using the eventType == TableModelEvent.INSERT.

Thanks in advance..
 
dhwani mathur
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok,fine i have shown a class below in which i have used tablemodellistener
check this , if it could help you in your program atleast to some extent.


import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;

public class JTableDemo extends JApplet
{
Object[][] data;

public JTableDemo(Object[][] data)
{
this.data=data;

}
private JTextArea txt = new JTextArea(4, 20);


class DataModel extends AbstractTableModel
{


// Prints data when table changes:
class TML implements TableModelListener
{
public void tableChanged(TableModelEvent e) {
txt.setText(""); // Clear it
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < data[0].length; j++)
txt.append(data[i][j] + " ");
txt.append("\n");
}
}
}

public DataModel() {
addTableModelListener(new TML());
}

public int getColumnCount() {
return data[0].length;
}

public int getRowCount() {
return data.length;
}

public Object getValueAt(int row, int col) {
return data[row][col];
}

public void setValueAt(Object val, int row, int col) {
data[row][col] = val;
// Indicate the change has happened:
fireTableDataChanged();

}

when you will create object of class JTableModel that is shown above,just call the run method and pass a data object as argument.The code for this is shown below.

JTableDemo tm=new JTableDemo(fq.data12);
tm.run(new JTableDemo(fq.data12), 350, 200);
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Naly", we don't have many rules here at JavaRanch but we do have a Naming Policy. Please review the policy and update your display name accordingly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!