• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Update cells of Table

 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
What is the function or method to update any cell of table in Java application or Applet? I am making simple application in which I have used array. I want to update value but not from any database just now. Here is my code:
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.awt.*;

public class SimpleTable2 extends JFrame{
Container con;
String[] columnNames = {"Printers","Model Name","Status"};
Object[][] rowData = {{"7020","IP-421","Ready"},
{"7040","IP-421J","Sleep"},
{"7050","IP-601","Waiting"}};

public SimpleTable2(){

super("Konica Copier Machines...");
con = this.getContentPane();
JTable table = new JTable(rowData,columnNames);
con.add(table.getTableHeader(),BorderLayout.NORTH);
con.add(table);
}

public static void main(String[] args)
{
SimpleTable2 frame = new SimpleTable2();
frame.pack();
frame.show();
}
}
Please let me know any method or function to update any cell of Table.
Thanks in advance,
Angela
 
maateen
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
U just add new object in array then it automatically update the table & draw it itself....
but still if there is any ambiguity then check out the following code it may help U....
//___________________________
//package swingchat;
import java.util.Vector;
import javax.swing.JLabel;
import java.awt.Color;
import javax.swing.JDialog;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.Color;
import javax.swing.JCheckBox;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.table.JTableHeader;
import java.awt.BorderLayout;
import java.awt.event.KeyEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
public class NoticeDisplay extends JDialog{
private javax.swing.JTable DBTable;
private javax.swing.JScrollPane tablePanel;
private JTableHeader tableHeader;
private JLabel label1;
private boolean diaplayableRecords=true;
private Vector columNames=null;
private Vector rowVector(final Vector data){
Vector tableVector=new Vector();
int j=0;
for(int i=0 ;i<data.size();j++){
Vector rowVector=new Vector();
rowVector.add(data.elementAt(j));
rowVector.add(data.elementAt(++j));
tableVector.add(rowVector);
i=i+2;
}
return tableVector;
}
public NoticeDisplay(final Vector messageList){
super.setTitle("Saved Messages Form Data Base.");
this.setSize(550,500);
this.setLocation(100,20);
this.setResizable(false);
columNames=new Vector();
columNames.add("Serial #");
columNames.add("Messages");
label1=new JLabel();
label1.setBorder(BorderFactory.createEtchedBorder());
label1.setBackground(Color.darkGray);
DBTable=new JTable(this.rowVector(messageList),columNames);
DBTable.setBorder(BorderFactory.createEtchedBorder());
tablePanel=new JScrollPane(DBTable);
tablePanel.setBorder(BorderFactory.createEtchedBorder());
tableHeader=DBTable.getTableHeader();
tableHeader.resizeAndRepaint();
tableHeader.setBorder(BorderFactory.createCompoundBorder());
this.getContentPane().add(tablePanel,BorderLayout.SOUTH);
this.getContentPane().add(label1,BorderLayout.NORTH);
this.getContentPane().setVisible(true);
this.setVisible(true);
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic