JTable refreshing

Hi everyone!
here is the problem.Though a different font & color
can be applied to each row of a JTable ,during the
process of refreshing(when i minimize & again maximize the
window,for example),the entire Jtable gets the (same)
colour and font that i applied last.Is there any way
to prevent it from getting repainted this way?Please help me out.Thanks anyway.                    
                    bharathch     

If I'm understanding this correctly, you are trying to set the color of the text (or background or whatever) on a row by row basis. If so, try using this renderer as a starting point...
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
public class TwoColorCellRenderer extends JLabel implements TableCellRenderer {
  public TwoColorCellRenderer() {
  public Component getTableCellRendererComponent(JTable table, Object value,
                                                 boolean isSelected, boolean hasFocus,
                                                 int row, int column) {
    if(value == null)
      this.setText("");
    else
      this.setText(value.toString());
    this.setOpaque(true);
    this.setForeground(Color.black);
    if(row%2 == 1)
      this.setBackground(Color.yellow);
    else
      this.setBackground(Color.white);
    return this;

Similar Messages

  • JTable refreshing... (I know this is over asked...)

    I know this is over asked, but I've spent the last 6hrs on here trying to figure out how to get this JTable(usersTxt) to refresh. I know I have to fire the right command, and I have to add a TableModelListener, I just don't understand how they interact, and what ACTUALLY refreshes the table on the screen..
    This section of the program is designed to read a list of users that is generated in the DataManager class(not included here), and then display them in a table, where a user can use buttons to modify the table. Here is the code:
    package AVCirc;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.event.TableModelEvent;
    import javax.swing.event.TableModelListener;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.event.ListSelectionEvent;
    public class UserEditor extends JFrame {
         static DefaultTableModel model = new DefaultTableModel();
         static JScrollPane scrollPane;
         static JTable usersTxt = new JTable();
         static ListSelectionModel usersLSM = usersTxt.getSelectionModel();
         static JButton addBtn = new JButton ("Add");
         static JButton delBtn = new JButton ("Delete");
         static JButton chgBtn = new JButton ("Change Password");
         static JButton adminBtn = new JButton ("Make Admin");
         static JTextField nameTxt = new JTextField ("");
         static JTextField passwordTxt = new JTextField ("");
         static JLabel nameLbl = new JLabel("Username:");
         static JLabel passwordLbl = new JLabel("(New)Password:");
         static Rectangle screenSize = AVCMethods.getVB();
         static String [] [] uStrArray;
         static User [] uArray;
         static String [] headArray = {"Priv", "Username", "Password"};
         static int rowSelected = 0;
         userListener l = new userListener(this);
         public UserEditor () {
              refreshList();
              getContentPane().setLayout(null);
              //Set up Window Listener ***********************************
              addWindowListener (new WindowAdapter () 
                public void windowClosing (WindowEvent e) 
                    dispose ();
            //Set up ListSelectionListener ***********************************
              usersLSM.addListSelectionListener(new ListSelectionListener() {
                  public void valueChanged(ListSelectionEvent e) {
                 //Ignore extra messages.
                 if (e.getValueIsAdjusting()) return;
                 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
                 if (lsm.isSelectionEmpty()) {
                     rowSelected = -1;
                 } else {
                     rowSelected = lsm.getMinSelectionIndex();
              model.addTableModelListener(new TableModelListener () {
                   public void tableChanged(TableModelEvent e) {
              scrollPane = new JScrollPane(usersTxt);
              scrollPane.setBounds(5, 45, 300, 450);
              usersTxt.getSelectionModel().setSelectionInterval(0, 0);
            usersTxt.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              addBtn.setBounds(310, 45, 180, 30);
              delBtn.setBounds(310, 80, 180, 30);
              chgBtn.setBounds(310, 115, 180, 30);
              adminBtn.setBounds(310, 150, 180, 30);
              nameLbl.setBounds(335, 185, 70, 20);
              passwordLbl.setBounds(305, 210, 100, 20);
              nameTxt.setBounds(410, 185, 80, 20);
              passwordTxt.setBounds(410, 210, 80, 20);
              getContentPane().add(scrollPane);
              getContentPane().add(nameLbl);
              getContentPane().add(passwordLbl);
              getContentPane().add(nameTxt);
              getContentPane().add(passwordTxt);
              getContentPane().add(addBtn);
              getContentPane().add(delBtn);
              getContentPane().add(chgBtn);
              getContentPane().add(adminBtn);
              if (addBtn.getActionListeners().length < 1) {
                   addBtn.addActionListener(l);
                   delBtn.addActionListener(l);
                   chgBtn.addActionListener(l);
                   adminBtn.addActionListener(l);
              setBounds(100, 100, 500, 600);
              setResizable(false);          
              setBackground(Color.gray);
              setTitle("AVCirc - User Editor");
              setVisible(true);
         public static class userListener implements ActionListener
             static UserEditor userWin;
             public userListener (UserEditor _a) {
                  userWin = _a;
            public void actionPerformed (ActionEvent evt) 
                  //Get the name of the activated object 
                Object mainSource = evt.getSource ();
                   if (rowSelected < 0) { new AlertWindow("You must make a selection!"); }
                   else {
                        String modStr = "";
                        User newU = new User((String)usersTxt.getValueAt(rowSelected, 1), (String)usersTxt.getValueAt(rowSelected, 2), "user ");
                     if (mainSource == addBtn) {
                          if (nameTxt.getText().length() <= 0 | passwordTxt.getText().length() <= 0) { new AlertWindow("You must fill in Username and Password!"); }
                             else { newU = new User(nameTxt.getText(), passwordTxt.getText(), "user "); modStr = "add"; }
                           } else if (mainSource == delBtn) {
                                modStr = "del";
                           } else if (mainSource == chgBtn) {
                            if (passwordTxt.getText().length() <= 0) { new AlertWindow("You must fill in the New Password field!"); }
                             else { newU = new User((String)usersTxt.getValueAt(rowSelected, 1), passwordTxt.getText(), "user "); modStr = "pass"; }
                           } else if (mainSource == adminBtn) {
                                modStr = "priv";
                           DataManager.modUser(modStr, newU);
                           refreshList();
            }// close actionPerformed method 
        }// close WidgetListener class
        public static void refreshList () {
             DataManager.genUsers();
             DataManager.sortUsers();
             uArray = DataManager.getUsers();
             uStrArray = new String [uArray.length] [3];
             for (int i = 0; i <= uStrArray.length - 1; i ++) {
                   uStrArray [0] = uArray [i].getPriv().trim();
                   uStrArray [i] [1] = uArray [i].getName().trim();
                   uStrArray [i] [2] = uArray [i].getPass().trim();
              model = new DefaultTableModel(uStrArray, headArray) {
    // Make read-only
    public boolean isCellEditable(int x, int y) {
    return false;
              model.setDataVector(uStrArray, headArray);
              model.fireTableDataChanged();
              usersTxt = new JTable(model);
              usersTxt.repaint((long)0);
    Near the end fo the code at the line: model.setDataVector.... is where I change the data, then you can see I try and fire the command, and then even repaint the table, but none of this seems to work.
    In the section where I add the TableModelListener(//...), I figure I'm supposed to add something there that actually refreshes the table but I'm not sure what.. I'm virtually in the dark from this point on :/
    Any suggestions/references? Any help is appreciated
    Thanks,
    -Visser

    Hi,
    I cannot see in your code where you're setting your model on the JTable.
    Note that the following line creates a new JTable and stores its reference in member usersTxt, but your scrollpane still holds the old table.
      usersTxt = new JTable(model);Change your code:
      static DefaultTableModel model = new DefaultTableModel();
      static JTable usersTxt = new JTable(model);
      public static void refreshList () {
        model.setDataVector(uStrArray, headArray);
        // nothing else here
      }By the way:
    - don't use static that often, I think what you really want are isntance members (non static)
    - Classes should start uppercase, e.g. UserListener
    Sven

  • JTable Refreshing problem for continuous data from socket

    Hi there,
    I am facing table refreshing problem. My table is filled with the data received from socket . The socket is receiving live data continuously. When ever data received by client socket, it notify table model to parse and refresh the data on specific row. The logic is working fine and data is refresh some time twice or some thrice, but then it seem like java table GUI is not refreshing. The data on client socket is continuously receiving but there is no refresh on table. I am confident on logic just because when ever I stop sending data from server, then client GUI refreshing it self with the data it received previous and buffered it.
    I have applied all the available solutions:
    i.e.
         - Used DefaultTableModel Class.
         - Created my own custem model class extend by AbstractTableModel.
         - Used SwingUtilities invokeLater and invokeAndWait methods.
         - Yield Stream Reader thread so, that GUI get time to refresh.
    Please if any one has any idea/solution for this issue, help me out.
    Here is the code.
    Custom Data Model Class
    package clients.tcp;
    import java.util.*;
    import javax.swing.table.*;
    import javax.swing.*;
    public class CustomModel extends DefaultTableModel implements Observer {
    /** Creates a new instance of CustomModel */
    public CustomModel() {
    //super(columnNames,25);
    String[] columnNames = {"Sno.","Symbol","BVol","Buy","Sale",
    "SVol","Last","..","...","Total Vol...",
    "..","High","..","Low","Change","Average","..."};
    super.setColumnIdentifiers(columnNames);
    super.setRowCount(25);
    /*This method called by client socket when ever it recived data as line/record*/
    public synchronized void update(Observable o, Object arg){
    collectData(arg.toString());
    /*This method used to parse, collect and notify table for new data arrival*/
    public synchronized void collectData(String rec){              
    String validSymbol="";
    System.out.println("collectDataRecord :-"+rec);
    StringTokenizer recToken=new StringTokenizer(rec," ");
    Vector rowVector=new Vector();
    for(int i=0;i<25;i++){
    validSymbol=(String)getValueAt(0,1);
    if(rec.indexOf(validSymbol) != -1){
    for(int j=0;recToken.hasMoreTokens();j++){
    super.setValueAt(recToken.nextToken(),i,j);
    //break;
    Client Socket Class
    package clients.tcp;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import javax.swing.*;
    public class DataReceiver extends Observable implements Runnable{
    private Socket TCPConnection = null;
    private BufferedReader br = null;
    private String serverName = "Salahuddin";
    private int serverPort = 5555;
    public DataReceiver()
    public void setServerName(String name){
    this.serverName=name;
    public void setServerPort(int port){
    this.serverPort=port;
    //03-20-04 12:30pm Method to open TCP/IP connection
    public void openTCPConnection()
    try
    TCPConnection = new Socket(serverName, serverPort);
    br = new BufferedReader(new InputStreamReader(
    TCPConnection.getInputStream()));           
    System.out.println("Connection open now....");
    //System.out.println("value is: "+br.readLine());
    }catch (UnknownHostException e){
    System.err.println("Don't know about host: ");
    }catch (IOException e){
    System.err.println("Couldn't get I/O for "
    + "the connection to: ");
    //03-20-04 12:30pm Method to receive the records
    public String receiveData(){
    String rec = null;
    try
    rec = br.readLine();          
    catch(IOException ioe)
    System.out.println("Error is: "+ioe);
    ioe.printStackTrace(System.out);
    catch(Exception ex)
    System.out.println("Exception is: "+ex);
    ex.printStackTrace(System.out);
    return rec;     
    public void run()
    while(true)
    String str=null;
    str = receiveData();
    if(str != null)
    /*try{
    final String finalstr=str;
    Runnable updateTables = new Runnable() {
    public void run() { */
    notifyAllObservers(str);
    SwingUtilities.invokeAndWait(updateTables);
    }catch(Exception ex){
    ex.printStackTrace(System.out);
    System.out.println("Observer Notified...");*/
    try{
    Thread.sleep(200);
    }catch(Exception e){
    public synchronized void notifyAllObservers(String str){
    try{
    setChanged();
    notifyObservers(str);
    }catch(Exception e){
    e.printStackTrace(System.out);
    Regards,
    Salahuddin Munshi.

    use your code to post codes more easy to read, lyke this:
    package clients.tcp;
    import java.util.*;
    import javax.swing.table.*;
    import javax.swing.*;
    public class CustomModel extends DefaultTableModel implements Observer {
    /** Creates a new instance of CustomModel */
    public CustomModel() {
    //super(columnNames,25);
    String[] columnNames = {"Sno.","Symbol","BVol","Buy","Sale",
    "SVol","Last","..","...","Total Vol...",
    "..","High","..","Low","Change","Average","..."};
    super.setColumnIdentifiers(columnNames);
    super.setRowCount(25);
    /*This method called by client socket when ever it recived data as line/record*/
    public synchronized void update(Observable o, Object arg){
    collectData(arg.toString());
    /*This method used to parse, collect and notify table for new data arrival*/
    public synchronized void collectData(String rec){
    String validSymbol="";
    System.out.println("collectDataRecord :-"+rec);
    StringTokenizer recToken=new StringTokenizer(rec," ");
    Vector rowVector=new Vector();
    for(int i=0;i<25;i++){
    validSymbol=(String)getValueAt(0,1);
    if(rec.indexOf(validSymbol) != -1){
    for(int j=0;recToken.hasMoreTokens();j++){
    super.setValueAt(recToken.nextToken(),i,j);
    //break;
    Client Socket Class

  • Refreshing Jtable data

    Hi:
    I am also working on a Application where I hav eto update my data (i.e. vector<vector>) for rows.
    Help is urgent.Since the data updated is overlapping.
    I have added my Jtable toa panel.
    and i put>>
    jtable.refresh();
    This idoesn't work.
    Thanking yu.
    Regards
    Ritesh

    Hi keene:
    I am attaching my source code.Please tell me where am I going wrong.
    Send me the modified code.
    to this email id:[email protected]
    Regards
    Ritesh
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    //Declare the Packages going to be imported here below
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.table.*;
    import java.util.*;
    import java.sql.*;
    //<Applet code="JApplicationSql.class" width=500 height=500></Applet>
    public class JApplicationSql extends JFrame implements ItemListener
         //Initialize the Components
         DefaultTableModel     defaulttablemodel;//     =     new DefaultTableModel();
         JTable          jtable     ;//=     new     JTable(defaulttablemodel);//A Dynamic Modifiable JTable
         Vector          row,column,row_1,column_1;//No. of rows and columns in a JTable
         JLabel label_combo=new JLabel();
         JComboBox comboBox =new JComboBox();
         JPanel jpanel;
         //comboBox.setEditable(true);
         //Declare the Container1
         Container contentPane;
         //Database Declarations
         //Connection connection;
         //String dbUrl = "jdbc:odbc:mydsn";
         //String user = "sa";
         //String password = "";
         private Statement stmt;
         private ResultSet rs;
         private ResultSetMetaData rmeta;
         String combo_value="";
         //String row_value="";
         //Initialization of Constructor
         public JApplicationSql()
              jpanel     =     new JPanel();
              label_combo.setText("Select the Department");
              label_combo.setFont(new Font("Verdana",1,17));
              comboBox.addItem(" 10 ");
              comboBox.addItem(" 20 ");
              comboBox.addItem(" 30 ");
              comboBox.addItem(" 40 ");          
              comboBox.addItem(" 50 ");
              //contentPane.setLayout(new FlowLayout());
              jpanel.add(label_combo);
              jpanel.add(comboBox);
              //Add the Listeners
              comboBox.addItemListener(this);
              contentPane     =     getContentPane();
              contentPane.add(jpanel,BorderLayout.NORTH);                    
              //Load the Drivers and Connection Objects and Establish the connection
              try
                   System.out.println("Locating Drivers");
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   System.out.println("Connecting to Database");
                   //connection = DriverManager.getConnection(dbUrl,user,password);
                   Connection connection = DriverManager.getConnection("jdbc:odbc:mydsn;UID=sa;PWD=");
                   System.out.println("Got Connection");
                   stmt = connection.createStatement();
              catch (Exception sqlex)
                   System.out.println("Unable to Connect!!");
                   sqlex.printStackTrace();
         public static void main(String args[])
              try
                   JApplicationSql app=new JApplicationSql();
                   app.setSize(500,350);
                   app.setVisible(true);
              }catch(Exception e)
         public void itemStateChanged(ItemEvent ite)     
              try
                   if (ite.getStateChange()==ItemEvent.SELECTED)
                        combo_value=(String)comboBox.getSelectedItem();
                        populate(combo_value);
                        jtable.repaint();
              catch(Exception SqlE)
                        System.out.println("Error in retrieving");
         //The Column Data
         public Vector retrieveColumns()
              column=new Vector();
              try
                   for(int i=1;i<=rmeta.getColumnCount();i++)
                             column.addElement(rmeta.getColumnName(i));
                   //System.out.println(column.size());
              catch(Exception e)
                   System.out.println("The column Exception is :"+e);
              return column;          
         //The Row Data
         public Vector retrieveRows()
              row=new Vector();
              try
                   while(rs.next())
                        Vector currow=new Vector();//Current Row     
                        for(int i=1;i<=rmeta.getColumnCount();i++)
                   currow.addElement(rs.getString(i));
                        System.out.println(currow.size());
                        row.addElement(currow);
         catch(SQLException se)
                   System.out.println("The Exception is :"+se);
              return row;          
         public void populate(String val)
              try
                   System.out.println("Value of the combo is "+val);
                   String sql_query="SELECT A.DeptId,A.EmpId,A.Name,A.Designation, B.DeptName FROM EmployeeDetails A,Master_Department B where A.DeptId = B.DeptId and A.DeptId ="+val;
                   //The Resultset Based Sql Query
                   //rs = stmt.executeQuery("SELECT EmployeeDetails.EmpId,EmployeeDetails.Name,EmployeeDetails.Designation, EmployeeDetails.DeptId,Master_Department.DeptName FROM EmployeeDetails INNER JOIN Master_Department ON EmployeeDetails.DeptId = 'index'");
                   rs=stmt.executeQuery(sql_query);
                   rmeta=rs.getMetaData();                                   
                   //Retrieve the number of columns and rows and add the number to Vectors
                   column_1= retrieveColumns();
                   //Row Data from the Vector Object
                   row_1=retrieveRows();
                   //Display the ResultSet data in a JTable
                   defaulttablemodel =new DefaultTableModel(row_1,column_1);
                   jtable =new JTable(defaulttablemodel);
                   defaulttablemodel.addTableModelListener(jtable);               
                   JScrollPane scrolltab=new JScrollPane(jtable);
                   jtable.setPreferredScrollableViewportSize(new Dimension(500, 70));
                   jpanel.add(scrolltab);
                   contentPane.add(scrolltab,BorderLayout.CENTER);
                   //jpanel.repaint();
                   //jtable.repaint();
                   //contentPane.add(jpanel,BorderLayout.CENTER);
                   //contentPane.validate(true);
              catch(Exception eop){System.out.println(eop);}

  • Refresh data in a jtable when data changes

    I have a jtable grdTable and a tableModel mytableModel which extend abstract table model
    I have a jcheckbox in the column 1 which i want to uncheck all
    I am doing the following.The data is changed ,I could see by doing susyem.out.println() but the data in the table does not refreshes.
    public void showTablechanges()
    TableModel tm = grdTable.getModel;
    for(int i=0 ;i<grdTable.getRowCount();i++)
    grdTable.setValueAt(Boolean.FALSE, i, 1);
    ( (MyTableModel)tm).fireTableDataChanged();
    grdTable.repaint();
    What am i missing or what wrong I am doing.How can i make the data refresh.
    I tried do a sys out after seting the value and it is showing as false but the checkbox is still checked.I have tried a lot of things but I am not able to refresh the jtable.
    Please please help.
    Thanks

    Thanks so much for the reply I read the links.I modified my code as
    public void showTablechanges() {
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    TableModel tm = grdTable.getModel;
    for (int i = 0; i < grdTable.getRowCount(); i++) {
    grdTable.setValueAt(Boolean.FALSE, i, 1);
    ((MyTableModel) tm).fireTableDataChanged();
    grdTable.repaint();
    This makes no difference.What strange thing is happening out of 12 checkboxes ,11 are unchecked but the first one always remains checked.EVen without the
    invoke later 11 are unchecked and 1 remains checked
    This method is in a panel and this panel is invoked from another MAin panel which has a changelistener for this panel.
    i.e if the method above is in myPanel.java then in my main panel,I have
    myPanel.addChangeListener(this)
    Also if i remove the line
    ((MyTableModel) tm).fireTableDataChanged();
    All checkboxes remains checked.
    I am really confused and this looks very tough to me ,Can you find out what is wrong
    Thanks,

  • To refresh the contents in JTextArea on selection of a row in JTable.

    This is the block of code that i have tried :
    import java.awt.GridBagConstraints;
    import java.awt.SystemColor;
    import java.awt.event.ActionEvent;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.ListSelectionModel;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.table.DefaultTableModel;
    import ui.layouts.ComponentsBox;
    import ui.layouts.GridPanel;
    import ui.layouts.LayoutConstants;
    import util.ui.UIUtil;
    public class ElectronicJournal extends GridPanel {
         private boolean DEBUG = false;
         private boolean ALLOW_COLUMN_SELECTION = false;
    private boolean ALLOW_ROW_SELECTION = true;
         private GridPanel jGPanel = new GridPanel();
         private GridPanel jGPanel1 = new GridPanel();
         private GridPanel jGPanel2 = new GridPanel();
         DefaultTableModel model;
         private JLabel jLblTillNo = UIUtil.getHeaderLabel("TillNo :");
         private JLabel jLblTillNoData = UIUtil.getBodyLabel("TILL123");
         private JLabel jLblData = UIUtil.getBodyLabel("Detailed View");
         private JTextArea textArea = new JTextArea();
         private JScrollPane spTimeEntryView = new JScrollPane();
         private JScrollPane pan = new JScrollPane();
         String html= " Item Description: Price Change \n Old Price: 40.00 \n New Price: 50.00 \n Authorized By:USER1123 \n";
         private JButton jBtnExporttoExcel = UIUtil.getButton(85,
                   "Export to Excel - F2", "");
         final String[] colHeads = { "Task No", "Data", "User ID", "Date Time",
                   "Description" };
         final Object[][] data = {
                   { "1", "50.00", "USER123", "12/10/2006 05:30", "Price Change" },
                   { "2", "100.00", "USER234", "15/10/2006 03:30", "Price Change12345"},
         final String[] colHeads1 = {"Detailed View" };
         final Object[][] data1 = {
                   { "Task:Price Change", "\n"," Old Price:50.00"," \n ","New Price:100.00"," \n" }
         JTable jtblTimeEntry = new JTable(data, colHeads);
         JTable jTbl1 = new JTable(data1,colHeads1);
         ComponentsBox jpBoxButton = new ComponentsBox(LayoutConstants.X_AXIS);
         public ElectronicJournal() {
              super();
              jtblTimeEntry.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              if (ALLOW_ROW_SELECTION) { // true by default
    ListSelectionModel rowSM = jtblTimeEntry.getSelectionModel();
    rowSM.addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
    //Ignore extra messages.
    if (e.getValueIsAdjusting()) return;
    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
    if (lsm.isSelectionEmpty()) {
    System.out.println("No rows are selected.");
    } else {
    int selectedRow = lsm.getMinSelectionIndex();
    System.out.println("Row " + selectedRow
    + " is now selected.");
    textArea.append("asd \n 123 \n");
    } else {
         jtblTimeEntry.setRowSelectionAllowed(false);
              if (DEBUG) {
                   jtblTimeEntry.addMouseListener(new MouseAdapter() {
         public void mouseClicked(MouseEvent e) {
         printDebugData(jtblTimeEntry);
              initialize();
         private void printDebugData(JTable table) {
    int numRows = table.getRowCount();
    int numCols = table.getColumnCount();
    javax.swing.table.TableModel model = table.getModel();
    System.out.println("Value of data: ");
    for (int i=0; i < numRows; i++) {
    System.out.print(" row " + i + ":");
    for (int j=0; j < numCols; j++) {
    System.out.print(" " + model.getValueAt(i, j));
    System.out.println();
    System.out.println("--------------------------");
         private void initialize() {
              this.setSize(680, 200);
              this.setBackground(java.awt.SystemColor.control);
              jBtnExporttoExcel.setBackground(SystemColor.control);
              ComponentsBox cmpRibbonHORZ = new ComponentsBox(LayoutConstants.X_AXIS);
              cmpRibbonHORZ.addComponent(jBtnExporttoExcel, false);
              jpBoxButton.add(cmpRibbonHORZ);
              this.addFilledComponent(jGPanel, 1, 1, 1, 1, GridBagConstraints.BOTH);
              this.addFilledComponent(jGPanel1, 2, 1, 11, 5, GridBagConstraints.BOTH);
              this.addFilledComponent(jGPanel2, 2, 13, 17, 5, GridBagConstraints.BOTH);
              jGPanel.setSize(650, 91);
              jGPanel.setBackground(SystemColor.control);
              jGPanel.addFilledComponent(jLblTillNo,1,1,GridBagConstraints.WEST);
              jGPanel.addFilledComponent(jLblTillNoData,1,10,GridBagConstraints.BOTH);
              jGPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,0,0,0));
              jGPanel1.setBackground(SystemColor.control);
              jGPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0,
                        0));
              spTimeEntryView.setViewportView(jtblTimeEntry);
              jGPanel1.addFilledComponent(spTimeEntryView, 1, 1, 11, 4,
                        GridBagConstraints.BOTH);
              jGPanel2.addFilledComponent(jLblData,1,1,GridBagConstraints.WEST);
              jGPanel2.setBackground(SystemColor.control);
              jGPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0,
                        0));
              //textArea.setText(html);
              pan.setViewportView(textArea);
         int selectedRow = jTbl1.getSelectedRow();
              System.out.println("selectedRow ::" +selectedRow);
              int colCount = jTbl1.getColumnCount();
              System.out.println("colCount ::" +colCount);
              StringBuffer buf = new StringBuffer();
              System.out.println("Out Of For");
              /*for(int count =0;count<colCount;count++)
              {System.out.println("Inside For");
              buf.append(jTbl1.getValueAt(selectedRow,count));
              // method 1 : Constructs a new text area with the specified text. 
              textArea  =new JTextArea(buf.toString());
              //method 2 :To Append the given string to the text area's current text.   
             textArea.append(buf.toString());
              jGPanel2.addFilledComponent(pan,2,1,5,5,GridBagConstraints.BOTH);
              this.addAnchoredComponent(jpBoxButton, 7, 5, 11, 5,
                        GridBagConstraints.CENTER);
    This code displays the same data on the JTextArea everytime i select each row,but my requirement is ,it has to refresh and display different datas in the JTextArea accordingly,as i select each row.Please help.Its urgent.
    Message was edited by: Samyuktha
    Samyuktha

    Please help.Its urgentThen why didn't you use the formatting tags to make it easier for use to read the code?
    Because of the above I didn't take a close look at your code, but i would suggest you should be using a ListSelectionListener to be notified when a row is selected, then you just populate the text area.

  • Refresh data in JTable

    hi, i hava a problem, i have a jtable where same Data column depend from another column of the same jtable and a jtextfield that is external to jtable
    my jtable is
    jcombobox | text | text | text ecc....
    when the user change the SelectedItem of jcombobox the other column`s data is jacombobox values * external JtextField text....
    if i change the value of the external jtextfield how can i refresh the data in the jtable whitout click over all cell???
    this is the code of the My CellRender of the first column:
    public class MyComboBoxRenderer extends JComboBox implements TableCellRenderer {
        JTable jt;
        PortataUgelli pug;
        public MyComboBoxRenderer(String[] items,JTable table,PortataUgelli pu) {
            super(items);
            this.jt=table;
            this.pug=pu;
            addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt){
                    if (jt.getSelectedColumn()==0){ //This action is only for the first column
                        String ugello= (String)getSelectedItem();
                        if (ugello==null) ugello=""+0;
                        double b=Double.parseDouble(pug.getPressione().trim());
                        String par="" + new VariID().getFunzioneUgelli(ugello,b); //this method calculate the value of the other cell
                        int sel;
                        if (jt.getSelectedRow() < 0) sel=0;
                        else sel = jt.getSelectedRow();
                        jt.setValueAt(par,sel,1); //set the value of the cell
        public Component getTableCellRendererComponent(JTable table, Object value,
                boolean isSelected, boolean hasFocus, int row, int column) {
            if (isSelected) {
                setForeground(table.getSelectionForeground());
                super.setBackground(table.getSelectionBackground());
            } else {
                setForeground(table.getForeground());
                setBackground(table.getBackground());
            // Select the current value
            setSelectedItem(value);
            return this;
    }

    It's fairly simple...
    you need to have your own custom TableModel. Extend AbstractTableModel and when you go to set a cell (to change the data in that cell) you simply fire an event with the:
    fireTableCellUpdated(int row, int column) method to let the view know that the data changed in that cell of that table changed and needs to be redrawn...
    Here's the link to the tutorial page/section on creating a custom table model and also firing events when data changes:
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#data

  • How to refresh an existing row of a JTable

    Hi all,
    I have to refresh the data of an existing row of a JTable after some time in thread. The code snippet is
    DefaultTableModel model=new DefaultTableModel(data,columnNames);
    table = new JTable(model)
                   public boolean isCellEditable(int row, int col)
                   return false;
    Now I also add rows to this table within the run() of the thread as
    model.addRow(new Object []{sub1,sub6,sub12,sub3,sub18});
    My problem is that I want to refresh the data of this added row within the thread.
    Any help is highly appreciable. Thanks in advance.
    Regards,
    Har Krishan

    Hmmm. His qhestion does not seem to be with how to change the value of a field, but how to get the table to recognize the change. I thought such things were automatic. The model fires a value changed event and the JTable picks up the event and refreshes. I'm not sure why your table is not refreshing under these circumstances. Perhaps a more complete code snippet. Please use the open and close code tags to format your code if you include it.

  • Refreshing the data in JTable

    I have a JTable which is linked to a table in the database.
    When i update a column in the database i want my Jtable to reflect the new value.
    How do i refresh the JTable data?
    Thanks in advance.
    Shrimon

    When a column is updated in the database, there is no event generated by the database to notify the Java application that the data has changed.
    If you are programatically updating a column in a database and have a related JTable in your application then you just use table.setValueAt(...) to reflect the updated value.

  • Problem: Is this how i update/refresh a JTable?

    Newbie in JTable and Swing here.
    I have created panel class which will load data from the database when first time come into this panel
    JScrollPane sp1 = new JScrollPane();
    PlayerTableModel pModel = new PlayerTableModel();
    JTable table1 = new JTable(pModel);
    upon a combobox change, i will refresh my table with new data...
    void cb_position_actionPerformed(ActionEvent e) {
    PlayerTableModel pModel = new PlayerTableModel(str_item);
    pModel.fireTableDataChanged();
    table1.repaint() ;
    but the above codes does not seems to refresh and update my table..
    help..
    Thanks...

    I have a piece of example code from a book that I've been working with lately. In this case when a certain combo box changes the table data is refreshed.
    Here is how it's done:
    if (scrollPane != null)
    getContentPane().remove(scrollPane);
    try
    String tableName= (String)tableNames.getSelectedItem();
    if (rs != null) rs.close();
    String query = "SELECT * FROM " + tableName;
    rs = stmt.executeQuery(query);
    if (SCROLLABLE)
    model = new ScrollingtbSchedule1Model(rs);
    else
    model = new CachingtbSchedule1Model(rs);
    JTable table = new JTable(model);
    scrollPane = new JScrollPane(table);
    getContentPane().add(scrollPane, "Center");
    pack();
    doLayout();
    catch(SQLException e)
    System.out.println("Error " + e);
    Notice that the pane is removed and then added again with the new data to force a "refresh".

  • How to refresh a JTable of a class from another thread class?

    there is an application, in server side ,there are four classes, one is a class called face class that create an JInternalFrame and on it screen a JTable, another is a class the a thread ,which accept socket from client, when it accept the client socket, it deal the data and insert into db,then notify the face class to refresh the JTable,but in the thread class I used JTable's revalidate() and updateUI() method, the JTable does not refresh ,how should i do, pls give me help ,thank you very much
    1,first file is a class that create a JInternalFrame,and on it there is a table
    public class OutFace{
    public JInternalFrame createOutFace(){
    JInternalFrame jf = new JInternalFram();
    TableModel tm = new MyTableModel();
    JTable jt = new JTable(tm);
    JScrollPane jsp = new JScrollPane();
    jsp.add(jt);
    jf.getContentPane().add(jsp);
    return jf;
    2,the second file is the main face ,there is a button,when press the button,screen the JInternalFrame. there is also a thread is beggining started .
    public class MainFace extends JFrame implements ActionListener,Runnable{
    JButton jb = new JButton("create JInternalFrame");
    jb.addActionListener(this);
    JFrame fram = new JFrame();
    public void performance(ActionEvent e){
    JInternalFrame jif = new OutFace().createOutFace(); frame.getContentPane().add(JInternalFrame,BorderLayout.CENTER);
    public static void main(String[] args){
    frame.getContentPane().add(jb,BorderLayout.NORTH);
    frame.pack();
    frame.setVisible(true);
    ServerSokct ss = new ServerSocket(10000);
    Socket skt = ss.accept()'
    new ServerThread(skt).start();
    3.the third file is a thread class, there is a serversoket ,and accept the client side data,and want to refresh the JTable of the JInternalFrame
    public class ServerThread extends Thread{
    private skt;
    public ServerThread(Sokcet skt){
    this.skt = skt;
    public void run(){
    OutputObjectStream oos = null;
    InputObjectStream ios = null;
    try{
    Boolean flag = flag;
    //here i want to refresh the JTable,how to write??
    catch(){}
    4.second is the TableModel
    public class MyTableModel{
    public TableModel createTableModel(){
    String[][] data = getData();
    TableModel tm = AbstractTableModel(
    return tm;
    public String[][] getData(){
    }

    Use the "code" formatting tags when posting code.
    Read this article on [url http://www.physci.org/codes/sscce.jsp]Creating a Simple Demo Program before posting any more code.
    Here is an example that updates a table from another thread:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=435487

  • JTable will not refresh with new data from database

    Hi,
    I have a JTable that does not recoginzed when the data has changed. The table is dynmaically populated with data from the database using a table model.
    Please help!!
    public JTable getUpdateContractTable() {
    QueryTableModel model;
    String [] dlrs = getSelectedDealers();
    String [] stats = getSelectedStatuses();
    String sql = buildContractQuery(dlrs, stats);
    try {
    if(isContractSet) {
    model = new QueryTableModel();
    model.setQuery(sql);
    table.setModel(model);
    table.setColumnModel(new UpdtCtrctColumnModel());
    table.invalidate();
    table.repaint();
    //model.fireTableChanged(new TableModelEvent(model));
    else {
    model = new QueryTableModel();
    UpdtCtrctColumnModel column = new UpdtCtrctColumnModel();
    model.setQuery(sql);
    table = new JTable(model, column);
    table.createDefaultColumnsFromModel();
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    model.fireTableChanged(null);
    isContractSet = true;
    catch (Exception e) {
    System.out.println(e.getMessage());
    //JOptionPane.show
    //.showMessageDialog("Error: " + e.getMessage(),
    // "Click Ok",
    // JOptionPane.INFORMATION_MESSAGE);
    return table;
    }

    thank you for your help. i finally got it to refresh. i have a follow-up question if you don't mind answering it. i have 2 jtables where one depends on the other. when i do a refresh i want the other table to disappear, so i call the getContentPane().remove(component), but the table doesn't disappear. what should i do.
    anthony

  • Problem of deletion of rows in jtable, table refreshing too

    Hi,
    I have a table with empty rows in the beginning with some custom properties( columns have fixed width...), later user would be adding to the rows to this table and can delete, I've a problem while deleting the rows from table,
    When a selected row is deleted the model is also deleting the data but the table(view) is not refreshed.
    Actually i'm selecting a cell of a row, then hitting the delete button.
    So the model is deleting the information, but i'm not able to c the fresh data in table( especially when the last cell of last row is selectd and hit the delete button, i am getting lots of exception)
    Kindly copy the below code and execute it, and let me know,
    * AuditPanel.java
    * Created on August 30, 2002, 3:05 AM
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.table.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.util.Vector;
    * @author yaman
    public class AuditPanel extends javax.swing.JPanel {
    // These are the combobox values
    private String[] acceptenceOptions;
    private Vector colNames;
    private Color rowSelectionBackground = Color.yellow;
    private int rowHeight = 20;
    private int column0Width =70;
    private int column1Width =96;
    private int column2Width =327;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    /** Creates new form AuditPanel */
    public AuditPanel() {
    public void renderPanel(){
    initComponents();
    public String[] getAcceptenceOptions(){
    return acceptenceOptions;
    public void setAcceptenceOptions(String[] acceptenceOptions){
    this.acceptenceOptions = acceptenceOptions;
    public Vector getColumnNames(){
    return colNames;
    public void setColumnNames(Vector colNames){
    this.colNames = colNames;
    public Vector getData(){
    Vector dataVector = new Vector();
    /*dataVector.add(null);
    dataVector.add(null);
    dataVector.add(null);
    return dataVector;
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;
    jPanel2 = new javax.swing.JPanel();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jPanel1 = new javax.swing.JPanel();
    jTable1 = new javax.swing.JTable();
    setLayout(new java.awt.GridBagLayout());
    setBorder(new javax.swing.border.EmptyBorder(0,0,0,0));
    jPanel2.setLayout(new java.awt.GridBagLayout());
    jPanel2.setBorder(new javax.swing.border.EmptyBorder(0,0,0,0));
    jButton1.setText("Add");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.ipadx = 8;
    gridBagConstraints.insets = new java.awt.Insets(0, 1, 5, 0);
    gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
    jPanel2.add(jButton1, gridBagConstraints);
    jButton2.setText("Delete");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
    jPanel2.add(jButton2, gridBagConstraints);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
    add(jPanel2, gridBagConstraints);
    jPanel1.setLayout(new java.awt.GridBagLayout());
    jPanel1.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.LOWERED, Color.black, Color.gray) );
    jTable1.setModel(new javax.swing.table.DefaultTableModel(getData(), getColumnNames()));
    // get all the columns and set the column required properties
    java.util.Enumeration enum = jTable1.getColumnModel().getColumns();
    while (enum.hasMoreElements()) {
    TableColumn column = (TableColumn)enum.nextElement();
    if( column.getModelIndex() == 0 ) {
    column.setPreferredWidth(column0Width);
    column.setCellEditor( new ValidateCellDataEditor(true) );
    if( column.getModelIndex() == 1) {
    column.setPreferredWidth(column1Width);
    column.setCellEditor(new AcceptenceComboBoxEditor(getAcceptenceOptions()));
    // If the cell should appear like a combobox in its
    // non-editing state, also set the combobox renderer
    //column.setCellRenderer(new AcceptenceComboBoxRenderer(getAcceptenceOptions()));
    if( column.getModelIndex() == 2 ) {
    column.setPreferredWidth(column2Width); // width of column
    column.setCellEditor( new ValidateCellDataEditor(false) );
    jScrollPane1 = new javax.swing.JScrollPane(jTable1);
    jScrollPane1.setPreferredSize(new java.awt.Dimension(480, 280));
    jTable1.setMinimumSize(new java.awt.Dimension(60, 70));
    //jTable1.setPreferredSize(new java.awt.Dimension(300, 70));
    //jScrollPane1.setViewportView(jTable1);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
    jPanel1.add(jScrollPane1, gridBagConstraints);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    add(jPanel1, gridBagConstraints);
    // set the row height
    jTable1.setRowHeight(rowHeight);
    // set selection color
    jTable1.setSelectionBackground(rowSelectionBackground);
    // set the single selection
    jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    // avoid table header to resize/ rearrange
    jTable1.getTableHeader().setReorderingAllowed(false);
    jTable1.getTableHeader().setResizingAllowed(false);
    // Table header font
    jTable1.getTableHeader().setFont( new Font( jTable1.getFont().getName(),Font.BOLD,jTable1.getFont().getSize() ) );
    jButton1.setMnemonic(KeyEvent.VK_A);
    // action of add button
    jButton1.addActionListener( new ActionListener(){
    public void actionPerformed(ActionEvent actionEvent){
    // If a button press is the trigger to leave a JTable cell and save the data in model
    if(jTable1.isEditing() ){
    //System.out.println("table is edition ");
    String text=((javax.swing.text.JTextComponent)jTable1.getEditorComponent()).getText();
    jTable1.setValueAt(text,jTable1.getSelectedRow(),jTable1.getSelectedColumn()) ;
    jTable1.getCellEditor().cancelCellEditing();
    // find out total available rows
    int totalRows = jTable1.getRowCount();
    int cols = jTable1.getModel().getColumnCount();
    if( jTable1.getModel() instanceof DefaultTableModel ) {
    ((DefaultTableModel)jTable1.getModel()).addRow(new Object[cols]);
    int newRowCount = jTable1.getRowCount();
    // select the first row
    jTable1.getSelectionModel().setSelectionInterval(newRowCount-1,newRowCount-1);
    jButton2.setMnemonic(KeyEvent.VK_D);
    // action of Delete button
    jButton2.addActionListener( new ActionListener(){
    public void actionPerformed(ActionEvent actionEvent){
    int totalRows = jTable1.getRowCount();
    // If there are more than one row in table then delete it
    if( totalRows > 0){
    int selectedOption = JOptionPane.showConfirmDialog(null,"Are you sure you want to delete this audit row?","Coeus", JOptionPane.YES_NO_OPTION);
    // if Yes then selectedOption is 0
    // if No then selectedOption is 1
    if(0 == selectedOption ){
    // get the selected row
    int selectedRow = jTable1.getSelectedRow();
    System.out.println("Selected Row "+selectedRow);
    if( selectedRow != -1 ){
    DefaultTableModel dm= (DefaultTableModel)jTable1.getModel();
    java.util.Vector v1=dm.getDataVector();
    System.out.println("BEFOE "+v1);
    v1.remove(selectedRow);
    jTable1.removeRowSelectionInterval(selectedRow,selectedRow);
    System.out.println("After "+v1);
    }else{
    // show the error message
    JOptionPane.showMessageDialog(null, "Please Select an audit Row", "Coeus", JOptionPane.ERROR_MESSAGE);
    } // end of initcomponents
    class AcceptenceComboBoxRenderer extends JComboBox implements TableCellRenderer {
    public AcceptenceComboBoxRenderer(String[] items) {
    super(items);
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus, int row, int column) {
    if (isSelected) {
    setForeground(table.getSelectionForeground());
    super.setBackground(rowSelectionBackground);
    } else {
    setForeground(table.getForeground());
    setBackground(table.getBackground());
    // Select the current value
    setSelectedItem(value);
    return this;
    class AcceptenceComboBoxEditor extends DefaultCellEditor {
    public AcceptenceComboBoxEditor(String[] items) {
    super(new JComboBox(items));
    } // end editor class
    public class ValidateCellDataEditor extends AbstractCellEditor implements TableCellEditor {
    // This is the component that will handle the editing of the
    // cell value
    JComponent component = new JTextField();
    boolean validate;
    public ValidateCellDataEditor(boolean validate){
    this.validate = validate;
    // This method is called when a cell value is edited by the user.
    public Component getTableCellEditorComponent(JTable table, Object value,
    boolean isSelected, int rowIndex, int vColIndex) {
    if (isSelected) {
    component.setBackground(rowSelectionBackground);
    // Configure the component with the specified value
    JTextField tfield =(JTextField)component;
    // if any vaidations to be done for this cell
    if(validate){
    //tfield.setDocument(new JTextFieldFilter(JTextFieldFilter.NUMERIC,4));
    tfield.setText( ((String)value));
    // Return the configured component
    return component;
    // This method is called when editing is completed.
    // It must return the new value to be stored in the cell.
    public Object getCellEditorValue() {
    return ((JTextField)component).getText();
    // This method is called just before the cell value
    // is saved. If the value is not valid, false should be returned.
    public boolean stopCellEditing() {
    String s = (String)getCellEditorValue();
    return super.stopCellEditing();
    public void itemStateChanged(ItemEvent e) {
    super.fireEditingStopped();
    }//end of ValidateCellDataEditor class
    public static void main(String args[]){
    JFrame frame = new JFrame();
    AuditPanel auditPanel = new AuditPanel();
    frame.getContentPane().add(auditPanel);
    auditPanel.setAcceptenceOptions(new String[]{"Accepted", "Rejected", "Requested"} );
    java.util.Vector colVector = new java.util.Vector();
    colVector.add("Fiscal Year");
    colVector.add("Audit Accepted");
    colVector.add("Comment" );
    auditPanel.setColumnNames( colVector);
    auditPanel.renderPanel();
    frame.pack();
    frame.show();

    Hi,
    I've got the solution for it. As when the cursor is in cell of
    a row and hit the delete button, the data in that cell is not saved,
    So i'm trying to save the data first into the model then firing the action event by doing this ..
    jButton2.addActionListener( new ActionListener(){       
    public void actionPerformed(ActionEvent actionEvent){           
    // If a button press is the trigger to leave a JTable cell and save the data in model
    if(jTable1.isEditing() ){                   
    String text=((javax.swing.text.JTextComponent)jTable1.getEditorComponent()).getText();
    jTable1.setValueAt(text,jTable1.getSelectedRow(),jTable1.getSelectedColumn()) ;
    jTable1.getCellEditor().cancelCellEditing();
    // HERE DO THE DELETE ROW OPERATION
    <yaman/>

  • Pls Help...Refreshing of JTable

    Hii,
    I am represinging data from database in JTable.I want it get refreshed and represent updated data.How can i do that
    Pls help me if u can
    Thanx
    Your Friend

    Hi,
    if your data model is a subclass of AbstractTableModel simply fireTableDataChanged() after you have updated your model - JTable is a table model listener to its model and will update its view accordingly. There are more fire.... methods in AbstractTableModel, choose that one, that reflects your changes best in order to avoid too much repaint action.
    greetings Marsian

  • Help!!! Refreshing  a JTable??

    Hi. i have a web site where things are bought, which in turn updates a table in a database, how can i view the orders as they are being made in a jtable dynamicaly. i can view the static table, i have tried to call the table method inside the javax.swing.timer and nothing happens, jus the same old static table. i just need to be able to refresh the jtable as the table expands in the database??

    Requery the database on your timer events and use the new result set to update the table.

Maybe you are looking for

  • OS 10.7.5 W' permissions repair problems. How to fix it?

    I have a 27" iMac running os 10.7.5 and i'm having permissions repair problems ever since my last os update,does anyone know whats going on and how to fix it? Any help or ideas would be appreciated.

  • My apple id and password doe not work on icloud

    My apple id and password works fine on everything else i do!!!! but it wont let me sign into i cloud!!!!! very ****** off!!! please help

  • Unable to view PDF forms

    I use adobe live cycle to create forms for use in our company, these forms must be editable by our mobile employees by way of free text field and drop down boxes. The form work fine on  a PC running Adobe Reader X but I am unable to edit them when us

  • G4 powerbook and G3 desktop with linksys help

    In either case, laptop, or g3, I can type in the linsys router address and get to config page, but on either - I cannot access the internet. On my laptop, wirelessly - I have tried the WPA password avenue and all kinds of different scenarios, then I

  • How to print a graphical interface

    Hi , I need to print a simple user interface in java. Highly appreciate your effort. Thanks, Uthpala