Updating a Jtable

Hi,
im trying to do a music library that connects to mysql.
My problem is that I dont know how to updatethe table after I have been modifying the database.
Ex.
I want to be able to import information to my database and then I want to see the changes instantly.
At the moment I only see the changes after a restart of the program.
My code:
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Vector;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import java.awt.Dimension;
import functions.*;
public class MusicLibrary extends JFrame implements ActionListener
     //DEFENITIONS
     JLabel north, south, deepSouth;
     JScrollPane scrollPane,scrollPane2;
     ImageIcon background,top,bottom;
     JTextField searchField;
     JButton searchButton;
     JTable table;
     JMenuBar menuBar;
     JMenu file;
     JMenuItem importSong,removeSong,close;
     Container c;
     public MusicLibrary()
          //MENU
          menuBar = new JMenuBar();
          file = new JMenu("File");
          file.setMnemonic(KeyEvent.VK_F);
          importSong = new JMenuItem("Import Song", KeyEvent.VK_I);
          removeSong = new JMenuItem("Remove Song", KeyEvent.VK_R);
          close = new JMenuItem("Close",KeyEvent.VK_C);
          setJMenuBar(menuBar);
          menuBar.add(file);
          file.add(importSong);
          file.add(removeSong);
          file.addSeparator();
          file.add(close);
          //SOUTH
          background = new ImageIcon("background.gif");
          south = new JLabel (background);
          //NORTH
          top = new ImageIcon("top.gif");
          north = new JLabel(top);
          north.setLayout(new FlowLayout());
          north.setBackground(new Color(0,0,0));
          searchField = new JTextField(50);
          searchButton = new JButton("Search");
          north.add(searchField);
          north.add(searchButton);
          //CONTAINER
          c = getContentPane();
          c.setLayout(new BorderLayout());
          c.add(north, BorderLayout.NORTH);
          setSize(800,620);
          setVisible(true);
          setResizable(false);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          //DEEP SOUTH
          bottom = new ImageIcon("bottom.gif");
          deepSouth = new JLabel(bottom);
          c.add(deepSouth, BorderLayout.SOUTH);
          //LISTENERS
          close.addActionListener(this);
          //searchField.addActionListener(this);
          searchButton.addActionListener(this);
          importSong.addActionListener(this);
          //DATABASE CONNECTION
          try {
               // load driver, create connection and statement
               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
               Connection con = DriverManager.getConnection("jdbc:odbc:XXX);
               Statement stmt = con.createStatement();
               // query database
               ResultSet rs = stmt.executeQuery("SELECT * FROM song");
               // display result
               getTable(rs);
               scrollPane = new JScrollPane(table);
               c.add(scrollPane, BorderLayout.CENTER);
               // close statement and connection
               stmt.close();
               con.close();
          catch (ClassNotFoundException e) {
               JOptionPane.showMessageDialog(null, e.toString(),
                    "ClassNotFoundException", JOptionPane.ERROR_MESSAGE);
               System.exit(1);
          catch (SQLException e) {
               JOptionPane.showMessageDialog(null, e.toString(),
                    "SQLException", JOptionPane.ERROR_MESSAGE);
               System.exit(1);
          //addWindowListener(new WindowHandler());
          setVisible(true);
     public void actionPerformed (ActionEvent e)
          if(e.getSource()==close)
               System.exit(0);
          else if(e.getSource()==searchButton)
               String textsearch = searchField.getText();
               JOptionPane.showMessageDialog(null,"You searched for " + textsearch);
               try {
                    // load driver, create connection and statement
                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                    Connection con = DriverManager.getConnection("jdbc:odbc:XXX);
                    Statement stmt = con.createStatement();
                    // query database
                    ResultSet rs = stmt.executeQuery("SELECT * FROM song WHERE Song_Name = 'Africa'");
                    // display result
                    getTable(rs);
                    stmt.close();
                    con.close();
               catch (ClassNotFoundException f) {
                    JOptionPane.showMessageDialog(null, f.toString(),
                         "ClassNotFoundException", JOptionPane.ERROR_MESSAGE);
                    System.exit(1);
               catch (SQLException f) {
                    JOptionPane.showMessageDialog(null, f.toString(),
                         "SQLException", JOptionPane.ERROR_MESSAGE);
                    System.exit(1);
          else if(e.getSource()==importSong)
               try
                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                    Connection con = DriverManager.getConnection("jdbc:odbc:XXX);
                    EditDatabase.importMp3(con);          
                    //TEST
                    Statement stmt = con.createStatement();
                    // query database
                    ResultSet rs = stmt.executeQuery("SELECT * FROM song");
                    // display result
                    getTable(rs);
                    stmt.close();
                    con.close();
               catch (Exception q){System.out.println("error" + q);}
          repaint();
     private void getTable(ResultSet rs) throws SQLException
          ResultSetMetaData rsmd = rs.getMetaData();
          Vector cols = new Vector();
          Vector rows = new Vector();
          // get column names
          for (int i = 1; i <= rsmd.getColumnCount(); i++) {
               cols.addElement(rsmd.getColumnName(i));
          // get rows
          while (rs.next()) {
               Vector nextRow = new Vector();
               for (int i = 1; i <= rsmd.getColumnCount(); i++) {
                    nextRow.addElement(rs.getString(i));
               rows.addElement(nextRow);
          // create table
          table = new JTable(rows, cols);
     //-WINDOW HANDLER-
     private class WindowHandler extends WindowAdapter
          public void windowClosing(WindowEvent e)
               System.exit(0);
     //-MAIN-
     public static void main (String[] arg)
          new MusicLibrary();
*Functions is a package containing importMp3 and deleteMp3
I really appreciate all the help I can get!

Thanks for poiting in the right direction.
I had to rethink the design and I stumbled upon some code of yours camickr, thanks.
Now the code looks like this:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import functions.*;
public class TableFromDatabase extends JFrame implements ActionListener, TableModelListener
     String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
     String url = "jdbc:odbc:mild";  // if using ODBC Data Source name
     String userid = "frenkan";
     String password = "tfb";
     Container c;
     JTable table;
     JScrollPane scrollPane;
     JMenuItem      importSong,
     removeSong,
     close;
     Connection connection;
     public TableFromDatabase()
          Vector columnNames = new Vector();
          Vector data = new Vector();
          try
               //  Connect to the Database               
               Class.forName( driver );
               Connection connection = DriverManager.getConnection( url, userid, password );
               //  Read data from a table
               String sql = "Select * from Song";
               Statement stmt = connection.createStatement();
               ResultSet rs = stmt.executeQuery( sql );
               ResultSetMetaData md = rs.getMetaData();
               int columns = md.getColumnCount();
               //  Get column names
               for (int i = 1; i <= columns; i++)
                    columnNames.addElement( md.getColumnName(i) );
               //  Get row data
               while (rs.next())
                    Vector row = new Vector(columns);
                    for (int i = 1; i <= columns; i++)
                         row.addElement( rs.getObject(i) );
                    data.addElement( row );
               rs.close();
               stmt.close();
          catch(Exception e)
               System.out.println( e );
          // Create TableModel with databases data
          DefaultTableModel model = new DefaultTableModel(data, columnNames);
          //model.addTableModelListener(this);
          //  Create table with model as TableModel
          table = new JTable(model)
               public Class getColumnClass(int column)
                    return getValueAt(0, column).getClass();
          scrollPane = new JScrollPane( table );
          getContentPane().add( scrollPane );
          JPanel buttonPanel = new JPanel();
          c = getContentPane();
          c.add( buttonPanel, BorderLayout.SOUTH );
          //MENU
          JMenuBar menuBar = new JMenuBar();
          JMenu file = new JMenu("File");
          importSong = new JMenuItem("Import Song");
          removeSong = new JMenuItem("Remove Song");
          close = new JMenuItem("Close");
          importSong.addActionListener(this);
          removeSong.addActionListener(this);
          close.addActionListener(this);
          setJMenuBar(menuBar);
          menuBar.add(file);
          file.add(importSong);
          file.add(removeSong);
          file.addSeparator();
          file.add(close);
     public void tableChanged(TableModelEvent e)
     public void actionPerformed (ActionEvent e)
          if (e.getSource() == close)
               System.exit(0);
          else if (e.getSource() == importSong)
               try
                    //  Connect to the Database               
                    Class.forName( driver );
                    Connection connection = DriverManager.getConnection( url, userid, password );
                    EditDatabase.importMp3(connection);
               catch (Exception exception)
                    System.out.println("Fel: " + exception);
     public static void main(String[] args)
          TableFromDatabase frame = new TableFromDatabase();
          frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
          frame.pack();
          frame.setVisible(true);
}Basicly the same as your with some few modifications.
What I want to know is how to update the table after I have imported a song to the database thru my importMp3() function? Please respond on a basic level. Any help is much appreciated!

Similar Messages

  • Updating a JTable when using an AbstractTableModel

    Hi,
    I have tried to create a JTable with an AbstractTableModel but I am obviously missing something in all the tutorials and examples as I cannot get the table to update when using my model.
    My application reads data in from a CSV file that is selectable at run time, but I have written a small app that demonstrates the problem I am having.
    If you uncomment the DefaultTableModel lines of code all is OK, but I need to use my Abstract Class as I intend to colour certain rows and add a Boolean column, that I would like to display as a CheckBox and not just the String representation.
    Any help would be great as I am tearing my hair out here!!
    My Test Class
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.util.*;
    public class TestTable extends JFrame implements ActionListener
    private JPanel jpTestTable = new JPanel();          
    private Vector vColumnNames = new Vector();
    private Vector vCellValues = new Vector();
    private DefaultTableModel dtmTestTable;
    private CustomTableModel ctmTestTable;
    private JTable jtTestTable;
    private JScrollPane jspTestTable;
    private JButton jbGo = new JButton();
         public TestTable()
         dtmTestTable = new DefaultTableModel();
         ctmTestTable = new CustomTableModel();
         //jtTestTable = new JTable( dtmTestTable );  //using this instead of my CustomModel works fine
         jtTestTable = new JTable( ctmTestTable );
         jtTestTable.setAutoCreateRowSorter(true);
         jtTestTable.setFillsViewportHeight( true );
         jspTestTable = new JScrollPane( jtTestTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS ,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
         jspTestTable.setBounds( 10, 10, 350, 400 );
         jspTestTable.setBorder( BorderFactory.createLoweredBevelBorder() );
         jbGo.setText( "Go" );
         jbGo.setBorder( BorderFactory.createRaisedBevelBorder() );
         jbGo.setBounds( 125, 430, 100, 25 );
         jbGo.addActionListener(this);
         jpTestTable.setLayout( null );
         jpTestTable.setBounds( 0, 0, 375, 500 );     
         jpTestTable.add( jspTestTable );
         jpTestTable.add( jbGo );
         this.setTitle( "Test Table" );
         this.getContentPane().setLayout( null );
         this.setBounds( 200, 50, 375, 500 );
         this.getContentPane().add( jpTestTable );
         this.setResizable( false );
         public void actionPerformed( ActionEvent e )
         updateTable();
         public void updateTable()
         vColumnNames.add( "Please" );
         vColumnNames.add( "work" );
         vColumnNames.add( "you" );
         vColumnNames.add( "git!" );
         vColumnNames.trimToSize();
         Vector vRow = new Vector();
              for( int i = 0; i < 10; i++ )
                   for( int x = 0; x < vColumnNames.size(); x++ )
                        vRow.add( "" + i + "" + x );
              vCellValues.add( vRow );
         //dtmTestTable.setDataVector( vCellValues, vColumnNames );  //using this instead of my CustomModel works fine
         ctmTestTable.setDataVector( vCellValues, vColumnNames );
         public void processWindowEvent(WindowEvent e)
         super.processWindowEvent(e);
              if(e.getID() == WindowEvent.WINDOW_CLOSING)
              exit();
         public void exit()
         System.exit( 0 );     
         public static void main(String args[])
         TestTable tt = new TestTable();
         tt.setVisible( true );
    }And my CustomTableModel Class
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.util.*;
    public class CustomTableModel extends AbstractTableModel
    protected Vector columnIdentifiers  = new Vector();
    protected Vector dataVector = new Vector();
         public CustomTableModel()
         public CustomTableModel( Vector data, Vector columnNames )
         setDataVector( data, columnNames );
         public int getColumnCount()
         return columnIdentifiers.size();
         public int getRowCount()
         return dataVector.size();
         public String getColumnName( int col )
         return "" + columnIdentifiers.get( col );
         public Object getValueAt( int row, int col )
         Vector vRow = new Vector();
         vRow = (Vector) dataVector.get( row );
         return (Object) vRow.get( col );
         public Class getColumnClass(int c)
         return getValueAt(0, c).getClass();
         public boolean isCellEditable(int row, int col)
              if (col < 2)
                   return false;
              else
                   return true;
         public void setValueAt( Object value, int row, int col )
         Vector vTemp = (Vector) dataVector.get( row );
         Vector<Object> vRow = new Vector<Object>();
              for( int i = 0; i < vTemp.size(); i++ )
                   vRow.add( (Object) vTemp.get( i ) );
         vRow.remove( col );
         vRow.add( col, value );
         vRow.trimToSize();     
         dataVector.remove( row );
         dataVector.add( row, vRow );
         dataVector.trimToSize();
         fireTableCellUpdated(row, col);
         public void setDataVector( Vector data, Vector columnNames )
         columnIdentifiers  = (Vector) columnNames.clone();
         dataVector = (Vector) data.clone();
         fireTableDataChanged();
    }I have just tried adding the following code after reading another example, but same result - arrrrrrrgggggggghhhhhhhhh!!!!
    ctmTestTable = (CustomTableModel) jtTestTable.getModel();
    ctmTestTable.fireTableDataChanged();Edited by: Mr_Bump180 on Jul 28, 2008 2:51 PM

    Hi camickr,
    Well that is good news as my Abstact class is about as much good as an ashtray on a motorbike. I think I must have misread or misunderstood the Table Tutorials as I thought I had to use an Abstrat class to get colurs based on conditions and to get Check Boxes to represent Boolean variables.
    I am clearly struggling with this concept - which I have never used before - do you know of any tutorials, that explain how to update a JTable with file data at runtime, as all the ones I have looked at set it as part of the java code - which is no good to me.
    Also am I overriding the DefaultTableModel Class correctly - I have written a seperate Model class but wounder if I need to include it in with my JTable class. I was trying to make it generic so I didn't have to write one for each JTable - but as I can't get it to work I should perhaps try to walk before I run.
    I'm not asking for the code, but just a guide to how close I am to where I want to be, and some links to tutorials that are closer to what I want to achieve. I will reread the Java Table Tutorial tonight - and you never know the penny may drop all on it's own this time!!!
    Thanks

  • How to Update the JTable Content

    Hi Friends
    In my Program i have a Form having a JTable with shows some content on it. Now when the User Click on the Row it will ask where he wants to Edit that rows content. If the User gives Yes. then the Another JDialog opens with the Selected rows Data.
    Now when the User makes changes in the Data and Clicks on the Edit Button. It Should Show the Entered Data on the JTable immediatly.
    I am Posting my working Code. It works fine. But only the Updating the Newly entered Data to the JTable is not done.
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.table.*;
    public class EditTable extends JDialog implements ActionListener,MouseListener
         private JRadioButton rby,rbn,rbr,rbnore,rbnorest;
         private ButtonGroup bg;
         private JPanel exportpanel;
         private JButton btnExpots;
         JTable table;
         JScrollPane scroll;
         public EditTable()throws Exception
              setSize(550,450);
              setTitle("Export Results");
              this.setLocation(100,100);
              String Heading[]={"BOOK ID","NAME","AUTHOR","PRICE"};
              String records[][]={{"B0201","JAVA PROGRAMING","JAMES","1234.00"},
                               {"B0202","SERVLET PROGRAMING","GOSLIN","1425.00"},
                               {"B0203","PHP DEVELOPMENT","SUNITHA","123"},
                               {"B0204","PRIAM","SELVI","1354"},
                               {"B0205","JAVA PROGRAMING","JAMES","1234.00"},
                               {"B0206","SERVLET PROGRAMING","GOSLIN","1425.00"},
                               {"B0207","PHP DEVELOPMENT","SUNITHA","123"},
                               {"B0208","PRIAM","SELVI","1354"}};
              btnExpots= new JButton("Export");
              btnExpots.addActionListener(this);
              btnExpots.setBounds(140,200,60,25);
              table = new JTable();
              table.addMouseListener(this);
              scroll=new JScrollPane(table);
              ((DefaultTableModel)table.getModel()).setDataVector(records,Heading);
              System.out.println(table.getModel());
              exportpanel= new JPanel();
              exportpanel.add(btnExpots,BorderLayout.SOUTH);
              exportpanel.add(scroll);
              getContentPane().add(exportpanel);
              setVisible(true);
          public void actionPerformed(ActionEvent ae)
         public static void main(String arg[]) throws Exception
              EditTable ex= new EditTable();
           public void mouseClicked(MouseEvent me)
              Object obj=me.getSource();
              if(obj==table)
                        JTable source=(JTable)me.getSource();
                        int row = source.rowAtPoint(me.getPoint());
                        int column = source.columnAtPoint(me.getPoint());
                        System.out.println("Working Point"+row+"and"+column);
                        Object value1 = source.getValueAt(row,0);     
                        Object value2 = source.getValueAt(row,1);
                        Object value3 = source.getValueAt(row,2);
                        Object value4 = source.getValueAt(row,3);
                        String bkId=value1.toString();
                        String bkNm=value2.toString();
                        String bkAuthr=value3.toString();
                        String bkAuthrCd=value4.toString();
                        int opt = JOptionPane.showConfirmDialog(this,"Do you Really Want to Edit this Book?","Edit Books",JOptionPane.YES_NO_OPTION);
                        if(opt==JOptionPane.YES_OPTION)
                             try
                                  editForm  editfrm= new editForm ();
                                  editfrm.setVisible(true);
                                  editfrm.setVisible(true);
                                  editfrm.txtbookID.setText(""+bkId);
                                  editfrm.txtbookName.setText(""+bkNm);
                                  editfrm.txtbookAuthorName.setText(""+bkAuthr);
                                  editfrm.txtPrice.setText(""+bkAuthrCd);
                             catch(Exception ex)
                                  ex.printStackTrace();
        public void mousePressed(MouseEvent e) {
        public void mouseReleased(MouseEvent e) {
        public void mouseEntered(MouseEvent e) {
        public void mouseExited(MouseEvent e) {
    class editForm extends JDialog implements ActionListener
         JLabel lblbookID,lblbookName,lblbookAuthorName,lblPrice;
         JTextField txtbookID,txtbookName,txtbookAuthorName,txtPrice;
         JButton btnEdit,btnClose;
         JPanel editPanel;
              public editForm()
                   setSize (350,400);
                   this.setTitle("Edit Books");
                   this.setLocation(100,135);
                   lblbookID= new JLabel("Book ID:");
                   lblbookID.setBounds (15, 15, 100, 20);
                   lblbookName= new JLabel("Book Name:");
                   lblbookName.setBounds (15, 45, 100, 20);
                   lblbookAuthorName= new JLabel("Author Name:");
                   lblbookAuthorName.setBounds (15, 75, 100, 20);
                   lblPrice= new JLabel("Price:");
                   lblPrice.setBounds (15, 105, 100, 20);
                   Font fnt = new Font("serif",Font.BOLD,18);
                   txtbookID= new JTextField();
                   txtbookID.setFont(fnt);
                   txtbookID.setEditable(false);
                   txtbookID.setBounds (120, 15, 175, 20);
                   txtbookName= new JTextField();
                   txtbookName.setFont(fnt);
                   txtbookName.setBounds (120, 45, 175, 20);
                   txtbookAuthorName= new JTextField();
                   txtbookAuthorName.setFont(fnt);
                   txtbookAuthorName.setBounds (120, 75, 175, 20);
                   txtPrice= new JTextField();
                   txtPrice.setFont(fnt);
                   txtPrice.setBounds (120, 105, 175, 20);
                   btnEdit = new JButton("Edit");
                   btnEdit.addActionListener(this);
                   btnEdit.setBounds (50, 295, 100, 25);
                   btnEdit.setMnemonic(KeyEvent.VK_E);
                   btnClose= new JButton("Close");
                   btnClose.addActionListener(this);
                   btnClose.setBounds (170, 295, 100, 25);
                   btnClose.setMnemonic(KeyEvent.VK_C);
                   editPanel = new JPanel();
                   editPanel.setLayout(null);
                   editPanel.add(lblbookID);
                   editPanel.add(lblbookName);
                   editPanel.add(lblbookAuthorName);
                   editPanel.add(lblPrice);
                   editPanel.add(txtbookID);
                   editPanel.add(txtbookName);
                   editPanel.add(txtbookAuthorName);
                   editPanel.add(txtPrice);
                   editPanel.add(btnEdit);
                   editPanel.add(btnClose);
                   getContentPane().add(editPanel);
                public void actionPerformed(ActionEvent ae)
    }Could anyone Please Run my code and Help me to Update the JTable Record.
    Thank you for your Help
    Cheers
    Jofin

    Your EditForm needs acces to the TableModel and the current row you are editing. Then when the user clicks the save button you simply use the TableModel.setValueAt(...) method to update the model and the table will be repainted automatically.

  • How do I update a JTable immediately after editing a cell?

    I have a JTable where I use a JComboBox to select a value in a cell. When a value is selected this updates another cell in the JTable.
    This works like I want to except for that I have to deselect the JComboBox (ie. click in another cell) before the other cell is updated.
    I want the cell to be updated when the JComboBox changes without having to deselect the JComboBox first.
    How can I do this?
    Thanks in advance for any help...
    Geir

    As an example I just copied the TableRenderDemo from the Swing-tutorial (http://java.sun.com/docs/books/tutorial/uiswing/components/table.html).
    The only change I have made to the TableRenderDemo is to replace the DefaultCellEditor with my own editor (ComboBoxEditor extends DefaultCellEditor).
    The only change I have made to the program itself is therefore to replace
    sportColumn.setCellEditor(new DefaultCellEditor(comboBox));*
    with
    sportColumn.setCellEditor(new ComboBoxEditor());*
    (And add the class ComboBoxEditor, of course.)
    When you run the original program, the default editor closes itself when a value is selected from the combobox. My editor doesen't close itself when a value is selected, but remais open until you click on another tablecell. I want my editor to close itself in the same way the DefaultCellEditor does.
    The code for TableRenderDemo is here: http://java.sun.com/docs/books/tutorial/uiswing/examples/components/TableRenderDemoProject/src/components/TableRenderDemo.java
    Again, to test what I mean just replace
    sportColumn.setCellEditor(new DefaultCellEditor(comboBox));*
    with
    sportColumn.setCellEditor(new ComboBoxEditor());*
    (And here is the code for my own celleditor:)
    private class ComboBoxEditor extends DefaultCellEditor {
    private JComboBox comboBox = null;
    public ComboBoxEditor(){
    super(new JComboBox());
    @Override public java.awt.Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,int row, int column){
    comboBox=new JComboBox();
    String name=(String)table.getValueAt(row,0);
    if(name.equals("Mary")){
    comboBox.addItem("Marys sport");
    comboBox.addItem("Marys cooking");
    else{
    comboBox.addItem("Other sport");
    comboBox.addItem("Other cooking");
    return comboBox;
    //else return super.getTableCellEditorComponent(table,value,isSelected,row,column);
    public void setCellEditorValue(Object newData){
    comboBox = (JComboBox) newData;
    @Override public Object getCellEditorValue(){
    return comboBox;
    }//end class

  • Updating a JTable using CachedRowSet data

    Hello, I would like to know how I can update my already created JTable receiving data from a CachedRowSet without creating a new table model (this is the method I have been using). I have read about using the fireTableDataChanged() method but I cant figure out how to use this works. Maybe an explanation on how the information in the CachedRowSet is updated in the JTable when notifiers are used will help.
    Any help will be appreciated

    camickr wrote:
    table.setAutoCreateColumnsFromModel( false );
    Perfect. This works well for my issue. I can now use the setModel() method without having the columns reordered.Damn camickr, that is a bloody good thing to know (it's often so much easier to recreate the table model, here's a very neat solution to one of the pitfalls)! Thanks :)
    Since this is solved, I still want to know how I can use the fireTableDataChanged() method and AbstractTableModel interface with CachedRowSet (just out of curiosity). I have been looking through jduprez's suggestion to figure this out too. I am currently faced with the issue,
    I have two classes, one for the CachedRowSet and the other with the table implementationsAs you describe it, I don't think that's a good approach: what I meant wad an implementation of TableModel , not a subclass of JTable : the stock JTable already knows how to work with any model implementation, as long as it implements TableModel .
    Where do I need to use the AbstractTableModel interface?It is a class, not an interface: it implements TableModel and provides useful defaults for some methods (at least, the management of the list of TableModelListener )
    My suggestion was that you define a custom class that extends AbstractTableModel , and uses its fireXxx judiciously.
    here is an example:
    public class RowSetAwareTableModel extends AbstractTableModel {
        public void setUpdateddata(RowSet newData) {
            this rowSet = newdata;
            super.fireTabledataChanged();
        /** Implementation of TableModel */
        public int getRowCount() {
            return rowset.getMaxRows();
        // etc...
    }

  • Updating a JTable using a JTable

    I am looking to update an empty JTable using the data from a JTable containing a set of data.
    I am aware that addRow can be used with the DefaultTableModel from previous discussions on this forum, but I have found this call isn't available when using AbstractTableModel.
    The reason I have been having some problems with this as it is necessary for the AbstractTableModel to be used in the context of the GUI, and I am asking if there is a way to solve this using the AbstractTableModel?
    I am using an AbstractTableModel for both the data table and the table showing all currently and previously selected rows.

    I am using an AbstractTableModel for both the data table and the table showing all currently and previously selected rows.No you aren't. You can't create an Abstract class because not all the methods are implements. You are using a class that extends AbstractTableModel.
    So why not use the DefaultTableModel and make your life simple?

  • Dynamically Updating a JTable

    I am developing an EPOS system using java, that uses a JTable to display the recipt, before it is printed.
    I have a class for the recipt data, stored in a vector which works and using observers fires events to the gui when things are added etc. My problem comes when i try to dynamically change the tables content, my idea was to create a new table, fill it with the new data, set the scroll pane around the new table and call revalidate to show the new table.
    This is possible but seems far too much work to just update a table! I would also assume the amount of extra garbage collection would require extra processing that seems pointless.
    Is there another way i could do it? Ideally i just want to refresh the content in the table for each update sent by the observable.
    Thanks

    Make your TableModel observe your observable and update it's contents. Remember to fire the appropriate event after the update.

  • Updating a JTable with an array of values

    Ther is a constructor that allows for the cretion of the table with an iniital array of values. However subsequent updates of blocks of data- say you received an array of updated data form a database- reuiqre you to update ince cell at a time. Is ther any way fo updating a whole block at once. I should point out that I am asking this because I am using JTables in the Matlab programming environment where arrays are the basic unit and looping through is a comparatively slow process

    Yes, you can extend the AbstractTableModel and write a method for updating a whole block.
    lets say you've got a Vector with Float[] arrays as elements to hold a 2D array of Float. The you could write:
          TableModel dataModel = new AbstractTableModel() {
                public int getColumnCount() { return col_names.size(); }
                public int getRowCount() { return data.size();}
                public Object getValueAt(int row, int col) {
                   return ((Float)((Float[])data.elementAt(row))[col]).toString();
                public String getColumnName(int col) {
                 return ((String)col_names.elementAt(col));
                public Class getColumnClass(int col) {
                 return String.class;
                public boolean isCellEditable(int row, int col) {
                  return true;
                public void setValueAt(Object aValue, int row, int col) {
                   try {
                     Float fv = Float.valueOf((String)aValue);
                    ((Float[])data.elementAt(row))[col] = fv;
                   } catch (Exception ex) {
                public void setBlock(Float block[][], int row, int col) {
                   // copy the Arrays with System.arrayCopy into data
          };PS: I don't know, if the above is correct written, havn't test this. But I hope you can recognize the idea behind it.
    wami

  • Trying to update a JTable w/ new info

    I've had some issue understanding the change events in the tutorial found here. http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#simple I've mostly gotten it, with the exception that my data does not change. I'm fairly certain it has to do with the tableChanged method. As always any help is GREATLY appreciated thanks.
    This is a simple JFrame containing a Table with a JButton that changes the value of my data variable.
    The tableChanged method is basically straight copied, what do I need to do for the entire table to update?
    package testtable;
    import javax.swing.JFrame;
    import javax.swing.JTable;
    import javax.swing.JScrollPane;
    import java.awt.Dimension;
    import java.awt.BorderLayout;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.table.TableModel;
    import javax.swing.event.TableModelListener;
    import javax.swing.event.TableModelEvent;
    import javax.swing.JButton;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    * @author rico
    public class TestTable implements TableModelListener {
        //this method is verbatim out of the tutorial
        public void tableChanged(TableModelEvent e) {
            int row = e.getFirstRow();
            int column = e.getColumn();
            TableModel model1 = (TableModel)e.getSource();
            String columnName = model.getColumnName(column);
            Object data3 = model.getValueAt(row, column);
            // Do something with the data...
            static String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};
            static Object[][] data = {
                {"Mary", "Campione",
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                 "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                 "Knitting", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                 "Speed reading", new Integer(20), new Boolean(true)},
                {"Philip", "Milne",
                 "Pool", new Integer(10), new Boolean(false)}
            static Object[][] data2 = {
                {"Cunt", "Campione",
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                 "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                 "muff-diving", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                 "Motor_boating", new Integer(20), new Boolean(true)},
                {"Philip", "Milne",
                 "Pool", new Integer(10), new Boolean(false)}
            static AbstractTableModel model = new AbstractTableModel() {
                public Object getValueAt(int row, int col) {
                    return data[row][col];
                public int getColumnCount() {
                    return columnNames.length;
                public int getRowCount() {
                    return data.length;
                @Override
                public void setValueAt(Object value, int row, int col) {
                    data[row][col] = value;
                    fireTableDataChanged();
         * @param args the command line arguments
        public static void main(String[] args) {
            JFrame frame = new JFrame("TestTable");
            frame.setSize(500, 500);
            JButton button = new JButton("button");
            button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    data = data2;
            JTable table = new JTable(model);
            table.getModel().addTableModelListener(table);
            JScrollPane pane = new JScrollPane(table);
            pane.setPreferredSize(new Dimension(400, 200));
            frame.add(pane, BorderLayout.NORTH);
            frame.add(button, BorderLayout.SOUTH);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
    }Edited by: rico16135 on Aug 30, 2008 4:13 AM

    There is no need to extend AbstractTableModel in this example.
    You can just create a DefaultTableModel using data and columnNames.
    If you want to display data2 inside the table create a new DefaultTableModel with data2 and use table.setModel to update the table.

  • Update of JTable

    Hi,
    I�ve change the data of a JTable from a Personal TableModel that inherites from AbstractTableModel.
    Anyone knows how to launch an update call so the Table is updated when I changed the internal data??
    Thanks,
    Al

    override void setValueAt(Object value, int row, int column);
    and call at the end fireTableCellUpdated(int row, int column);

  • Updating a JTable by hiding/displaying columns

    I have a customizable JTable where I display/hide columns according to a users' selection criteria. My code works fine for hiding/displaying columns if the Jtable is opened for the fist time, but doesnot work if I want to hide columns in already displayed table.How do I do it?? Any clue?? I tried
    myTabModel.fireTableDataChanged();
    but this only works for updating the table data...it does not hide columns for me... when I hide column I just remove desired column like this:
    myTable.removeColumn(myTable.getColumn("Column 3"));

    Here is the sample code I tried. It worked without any invalidate or repaint or updateUI(). generated using NetBeans
    check for <==== for the line of code doing this
    * TableTest.java
    * Created on October 9, 2002, 1:42 PM
    * @author  Anki Reddy Nelaturu
    public class TableTest extends javax.swing.JFrame {
        /** Creates new form TableTest */
        public TableTest() {
            initComponents();
        /** 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() {
            jScrollPane1 = new javax.swing.JScrollPane();
            jTable1 = new javax.swing.JTable();
            jButton1 = new javax.swing.JButton();
            jTextField1 = new javax.swing.JTextField();
            menuBar = new javax.swing.JMenuBar();
            fileMenu = new javax.swing.JMenu();
            openMenuItem = new javax.swing.JMenuItem();
            saveMenuItem = new javax.swing.JMenuItem();
            saveAsMenuItem = new javax.swing.JMenuItem();
            exitMenuItem = new javax.swing.JMenuItem();
            editMenu = new javax.swing.JMenu();
            cutMenuItem = new javax.swing.JMenuItem();
            copyMenuItem = new javax.swing.JMenuItem();
            pasteMenuItem = new javax.swing.JMenuItem();
            deleteMenuItem = new javax.swing.JMenuItem();
            helpMenu = new javax.swing.JMenu();
            contentsMenuItem = new javax.swing.JMenuItem();
            aboutMenuItem = new javax.swing.JMenuItem();
            getContentPane().setLayout(null);
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            jTable1.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null}
                new String [] {
                    "Title 1", "Title 2", "Title 3", "Title 4"
            jScrollPane1.setViewportView(jTable1);
            getContentPane().add(jScrollPane1);
            jScrollPane1.setBounds(80, 30, 230, 120);
            jButton1.setText("jButton1");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
            getContentPane().add(jButton1);
            jButton1.setBounds(170, 180, 81, 26);
            jTextField1.setText("jTextField1");
            getContentPane().add(jTextField1);
            jTextField1.setBounds(60, 190, 63, 20);
            fileMenu.setText("File");
            openMenuItem.setText("Open");
            fileMenu.add(openMenuItem);
            saveMenuItem.setText("Save");
            fileMenu.add(saveMenuItem);
            saveAsMenuItem.setText("Save As ...");
            fileMenu.add(saveAsMenuItem);
            exitMenuItem.setText("Exit");
            exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    exitMenuItemActionPerformed(evt);
            fileMenu.add(exitMenuItem);
            menuBar.add(fileMenu);
            editMenu.setText("Edit");
            cutMenuItem.setText("Cut");
            editMenu.add(cutMenuItem);
            copyMenuItem.setText("Copy");
            editMenu.add(copyMenuItem);
            pasteMenuItem.setText("Paste");
            editMenu.add(pasteMenuItem);
            deleteMenuItem.setText("Delete");
            editMenu.add(deleteMenuItem);
            menuBar.add(editMenu);
            helpMenu.setText("Help");
            contentsMenuItem.setText("Contents");
            helpMenu.add(contentsMenuItem);
            aboutMenuItem.setText("About");
            helpMenu.add(aboutMenuItem);
            menuBar.add(helpMenu);
            setJMenuBar(menuBar);
            pack();
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            jTable1.removeColumn(jTable1.getColumnModel().getColumn(Integer.parseInt(jTextField1.getText())));        // <========
        private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
            System.exit(0);
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
         * @param args the command line arguments
        public static void main(String args[]) {
            new TableTest().show();
        // Variables declaration - do not modify
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JMenu fileMenu;
        private javax.swing.JMenuItem exitMenuItem;
        private javax.swing.JButton jButton1;
        private javax.swing.JMenuItem saveAsMenuItem;
        private javax.swing.JMenuItem saveMenuItem;
        private javax.swing.JMenuItem copyMenuItem;
        private javax.swing.JMenuItem pasteMenuItem;
        private javax.swing.JMenuItem cutMenuItem;
        private javax.swing.JMenuItem openMenuItem;
        private javax.swing.JMenuBar menuBar;
        private javax.swing.JMenu editMenu;
        private javax.swing.JMenuItem aboutMenuItem;
        private javax.swing.JMenuItem contentsMenuItem;
        private javax.swing.JMenu helpMenu;
        private javax.swing.JTextField jTextField1;
        private javax.swing.JMenuItem deleteMenuItem;
        private javax.swing.JTable jTable1;
        // End of variables declaration
    }

  • Update a JTable placed on a TabbedPane

    Hi,
    I have an application which consist of a tabbedPane, and each tabbedPane(4) consist of a JTable. But when I make a spesific selection (query) in the tabbedPane (through a comboBox), where the tabbedPane has the index-value of 2, its the last JTable which gets updated, where the tabbedPane has the index-value of 3. This is how I create the gui:
    public void setTabbedPaneGUI(){
        sqlArtist = sqlCon.sqlArtist() ;
        dualCombo = new DualComboBox(this, sqlArtist) ;
        for(int i = 0; i < 4; i++){           
            if(i == 0)
                sqlQuery = sqlCon.sqlDefaultBandValue() ;           
            else if(i == 1)
                sqlQuery = sqlCon.sqlDefaultReleaseValue() ;           
            else if(i == 2)
                 sqlQuery = sqlCon.sqlDefaultTrackValue() ;           
            else if(i == 3)
                 sqlQuery = sqlCon.sqlDefaultBandValue() ;           
            JPanel panel = new JPanel() ;
            buttonTool = new ButtonTool() ;
            tableClass = new TableClass(this, sqlQuery, i) ;
            bandText = new BandFieldGUI() ;
            panel.setLayout(new BorderLayout()) ;
            panel.add(buttonTool, BorderLayout.WEST) ;
            panel.add(tableClass, BorderLayout.CENTER) ;
            panel.add(bandText, BorderLayout.SOUTH) ;
            if(i == 2)
                panel.add(dualCombo, BorderLayout.NORTH) ;           
            tabbedPane.addTab(" ", panel) ;
    }my update method in the gui-class:
    public void updateTableClass(String b){
        if(getSelectedIndex() == 2){            
            String ElementB = b ;
            String update = sqlCon.refreshTrackTable(ElementB) ;
            System.out.println(update) ;
            tableClass.updateTable(update) ;
    }my update method in tableclass:
    public void updateTable(String u){
        String update = "" ;
        update = u ;     
        if(getTabbedPaneIndex() == 2){
            index = 2 ;
            System.out.println(update) ;      
        try{       
            tableModel.setQuery(update) ;
        catch(SQLException sqle){
            JOptionPane.showMessageDialog(null, sqle.getMessage(),
            "Error", JOptionPane.ERROR_MESSAGE) ;
    }Can anyone tell me how I can get update the correct JTable? The update method works except it updates the wrong JTable.
    gmtongar

    Hmm.. Weird..
    I had some problems just like yours, but, first it was
    without the .revalidade(). I put it and nothing, then
    i put the fireTableUpdated() at the model, then it
    worked fine!...
    Sorry cant help ya...
    But, just curious, are doing something like an
    internal email???If so, are u using any database, or
    only in java??
    Tks,
    BrunoWell, I�m close now. It seems to be something funny with the JTable because when I update the text on a JButton instead it works. I think I�m gonna use a JList instead, maybe that works better. I�ve figured out now that a JTable was a little overkill for my app.
    The app that I�m developing is thought to be a conference system with broadcasted audio and video. My specific problem regards the list with the connected users...
    /P

  • Update only JTable/ViewObject

    Is there a method to declare a JTable in JDeveloper as update only where insert and delete are not allowed and the navigation bar would show the insert/delete buttons as disabled for the view object?

    John,
    you can mark the View object attributes as read only, or add teh following code for the navigation bar
    private JUNavigationBar navBar = new JUNavigationBar();
    navBar.setHasInsertButton(false);
    navBar.setHasDeleteButton(false); navBar.setHasTransactionButtons(false);
    A third option is to change the JTable component itself, changing the table model.
    Frank

  • AbstractTableModel not updating the JTable...

    I need to fix this probelm very urgently... Running out of time...
    Pleas see the code below. I am trying to add a new row to the JTable using two classes. as given below...
    Problem:-
    1) Any new row added is getting added to the first row and the table always shows only the recently added record (at first row).
    2)."public synchronised void updatePlayer(String[] ptyprrecord)" Method in PTypeInfoModel is giving problem in firing table change...
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    import javax.swing.table.TableColumn;
    public class SerjProType {
    public JTable ProTypeTable;
    public String ColumnNames[];
    public String DataValues[][];
    public JFrame jframe;
    public PTypeInfoModel ProInfoModel;
    public int rownum = 0;
    public String[] data = new String[4];
    /** Creates a new instance of SerjProType */
    public SerjProType() {        
    //createColumn();
    //createData();
    jframe = new JFrame(" Testing Abstract Table Model");
    ProInfoModel = new PTypeInfoModel();
    ProTypeTable = new JTable(ProInfoModel);
    TableColumn tc = null;
    for(int i=1;i<4;i++){
    tc = ProTypeTable.getColumnModel().getColumn(i);
    tc.setCellRenderer(new SummColmColorRenderer());
    ProTypeTable.setPreferredScrollableViewportSize(new Dimension(600, 200));
    ProTypeTable.setSelectionBackground(Color.lightGray);
    ProTypeTable.addMouseListener(new MouseAdapter(){
    public void mouseClicked(MouseEvent e){
    if(e.getClickCount()==2){
    System.out.println("This is being clicked");
    new SerjInstDet();
    JScrollPane jsp = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    jsp.getViewport().add(ProTypeTable);
    JButton fireRowbutton = new JButton("Fire Row Update...");
    fireRowbutton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent ae){                   
    rownum++;
    data[0] = "PTYPEee"+rownum+" :-) ";
    System.out.println("Value of data[0] -- "+data[0]);
    data[1] = "12";
    data[2] = "13";
    data[3] = "13";
    ProInfoModel.updatePlayer(data);
    //add(fireRowbutton);
    JButton fireCellbutton = new JButton("Fire Cell Update...");
    fireCellbutton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent ae){
    //add(fireCellbutton);
    JPanel jpane = new JPanel();
    jpane.add(jsp);
    jpane.add(fireRowbutton);
    jpane.add(fireCellbutton);
    jframe.getContentPane().add(jpane);
    jframe.setSize(600,400);
    jframe.setVisible(true);
    //setSize(500,200);
    //show();
    //setTitle("Process Type");
    public static void main(String args[]){
    new SerjProType();
    import java.util.Vector;
    import javax.swing.table.AbstractTableModel;
    public class PTypeInfoModel extends AbstractTableModel {   
    protected static int NUM_COLUMNS = 4;
    protected static int START_NUM_ROWS = 0;
    protected int nextEmptyRow = 0;
    protected int numRows = 0;
    static final public String Ptype_name ="Process Type";
    static final public String Ok_Inst = "Ok";
    static final public String OnHold_inst = "On Hold";
    static final public String Late_Inst = "Late";
    protected Vector data = null;
    /** Creates a new instance of PTypeInfoModel */
    public PTypeInfoModel() {
    data = new Vector();
    public String getColumnName(int column) {
         switch (column) {
         case 0:
         return Ptype_name;
         case 1:
         return Ok_Inst;
         case 2:
         return OnHold_inst;
         case 3:
         return Late_Inst;
         return "";
    public synchronized int getColumnCount() {
    return NUM_COLUMNS;
    public synchronized int getRowCount() {
    if (numRows < START_NUM_ROWS) {
    return START_NUM_ROWS;
    } else {
    return numRows;
    public synchronized Object getValueAt(int row, int column) {
         try {
    String[] w = (String[])data.elementAt(row);
    switch (column) {
    case 0:
    return w[0];
    case 1:
    return w[1];
    case 2:
    return w[2];
    case 3:
    return w[3];
         } catch (Exception e) {
         return "";
    public synchronized void updatePlayer(String[] PTypeRecord) {     
    String PTypeName = PTypeRecord[0]; //find the Name
    String[] p = null;
    int index = -1;
    boolean found = false;
         boolean addedRow = false;
    int i = 0;
    int vecsize = data.size();
    if (vecsize == 0){}
    else{
    for (int l=0;l<vecsize;l++){
    String[] q = (String[])data.elementAt(l);
    for(int m=0;m<q.length;m++){
    System.out.println("Vector Content "+ q[m]);
    while (!found && (i < nextEmptyRow)) {
    p = (String[])data.elementAt(i);
    System.out.println("value of p[o] -- "+p[0]);
    System.out.println("value of PTypeName is -- "+PTypeName);
    String pofzero = p[0];
    if (PTypeName.equalsIgnoreCase(pofzero)) {
    found = true;
    index = i;
    } else {
    i++;
    if (found) { //update old player
         data.setElementAt(PTypeRecord, index);
    } else { //add new player
         if (numRows <= nextEmptyRow) {
              //add a row
    numRows++;
              addedRow = true;
    index = nextEmptyRow;
         data.addElement(PTypeRecord);
    nextEmptyRow++;
         //Notify listeners that the data changed.
         if (addedRow) {
         fireTableRowsInserted(index,index);
         } else {
         fireTableRowsUpdated(index, index);
    public synchronized void clear() {
         int oldNumRows = numRows;
    numRows = START_NUM_ROWS;
         data.removeAllElements();
    nextEmptyRow = 0;
         if (oldNumRows > START_NUM_ROWS) {
         fireTableRowsDeleted(START_NUM_ROWS, oldNumRows - 1);
         fireTableRowsUpdated(0, START_NUM_ROWS - 1);
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    My guess is that your variable "index" has a wrong value: toward the end, when you check the variable "addedRow", you use the variable "index" to notify which row was inserted/updated. However, I can see a few lines before that this very same variable, "index", is incremented even if "addedRow" has been set. Most probably, in the best case scenario, this variable will point 1 row too far.
    I haven't launched the program nor read it extensively, so it is more a quick guess than anything else. If it isn't the problem, I would advise you to check what exactly the program does at the end: is the variable "addedRow" set or not, does the variable "index" point to the right row, and if yes, is the event forwarded to the correct place, etc...

  • Update a JTable

    I have a client-server application that uses a JTable on both sides. Either the client or the server sends a message to the other and that message should appear in both JTables. Hard to explain...
    My problem is that the message does not appear in the JTable during runtime. When a message is sent between the two apps I know that it is recieved and that the data is intact. The data is added to tablemodel but the JTable is not updated. Why?
    When I call the exact same method locally using a simple JButton it works fine.
    Client-GUI: Send message to server ->
    Client-ControlClass -> Sends message to server over RMI
    Server Control-> Recieves message and calls method in GUI
    Server GUI->Recives message and updates the tablemodel but not the JTable.
    Server-GUI: JButton is pressed, calls the same method as in step 4 above. Works fine...
    Here is the method, nothing advanced.
    public void addUser(User user)
    System.out.println("Adduser called"+user);
    tableModel.addRow(new String[] {user.getName(), ""});
    I use the DefaultTableModel.
    Any ideas?
    Cheers!
    /Pontus

    Hmm.. Weird..
    I had some problems just like yours, but, first it was
    without the .revalidade(). I put it and nothing, then
    i put the fireTableUpdated() at the model, then it
    worked fine!...
    Sorry cant help ya...
    But, just curious, are doing something like an
    internal email???If so, are u using any database, or
    only in java??
    Tks,
    BrunoWell, I�m close now. It seems to be something funny with the JTable because when I update the text on a JButton instead it works. I think I�m gonna use a JList instead, maybe that works better. I�ve figured out now that a JTable was a little overkill for my app.
    The app that I�m developing is thought to be a conference system with broadcasted audio and video. My specific problem regards the list with the connected users...
    /P

Maybe you are looking for

  • ALV hierarchy report

    Hi, I am trying to create ALV report using FM: REUSE_ALV_HIERSEQ_LIST_DISPLAY My Report format is as follows: Shipto1 <Level 1>      Shipping plant1  <Level 2>          VBELN POSNR  <Level 3>          VBELN POSNR  <Level 3>          VBELN POSNR  <Lev

  • Are Solaris Patches ONLY available for a fee?

    I have tried repeatedly to get Patch Manager for Solaris 9, which we're running on a brand new V240. The application we purchased it for is not yet certified to be binary compatible with SOL 10, so we were forced to go back to SOL9. SunSolve makes Pa

  • Wifi not working with Windows Vista - BT in denial

    I run a laptop repair centre in Dundee and have BT Business Broadband which was working fine until a few days ago. Now, any vista machine refuses to connect to the wifi while XP and Windows 7 are unaffected. I have hundreds of laptops in stock at any

  • Self-assigned IP of death

    My MacBook never did this on 10.4.10, but it's done it from the second I installed 10.4.11, as well as 10.5.1 now. Whenever I wake the MacBook from sleep, it is able to tell me the existence of our home router (over Airport), it says it connects to i

  • Planned delivery days on contract is not executed on the PO

    Hi We have added a number of planned delivery days on each material on a contract. In my understanding the number of days added here, should be added to the delivery date on the PO (doc date + no of planned del. Days from contract). This does not wor