Refreshing JTable (JDBC)

Hi there!
I would like to ask your help regarding JTable.
I am just new in Java comming from VB. I really cannot understand how JTable works.. since in VB it is very easy to refresh the table/grid.
Any one who got a simple program (Even using MS Access) that will display DB Table's content to a JTable object and will be able to refresh JTable's content everytime a record is updated? (Even the refreshing of table side only).
Hope you guys can help me with this since its been weeks already looking for a sample and explanation which is easy to understand.
Thanks!

have you tried sun's tutorial: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html ?
JTable is implemented with a data model (table model) as its data container.
So you need to update the table model first before re-displaying your table. :)

Similar Messages

  • Please Help! - Refreshing a JTable ( JDBC)

    Hi
    Currently I am populating a JTable with data from an Access database.
    I have not yet created my own Table Model.
    My table is displayed in a frame with a button to the side which when clicked creates a dialog box which enables the user to input data. Clicking the OK button on this dialog box then updates the database and the dialog box is removed.
    The problem is that the table is not updated with this newly input data.
    I have tried using
    ((AbstractTableModel)table1.getModel()).fireTableDataChanged();
    which doesn't work.
    If I create my own Table Model and then call on the fireTableDataChanged method,will this update the table? I want the table to update as soon as the dialog box is closed.
    I really would appreciate any help here. The JTable tutorial doesn't really help.
    Thanks
    LGS

    Would you agree that it would be better to requery the database incase another user has subsequently posted new recordsConcurrency shouldn't be a problem, but if it buys you peace of mind, then do it.
    Also -are you saying that I really should have my own Table Model? You should, this will give you more control over the operations of the table.
    If you want to see how I implement DB access in my table, check out the imports from and exports to external databases at the link shown below:
    http://www.aokabc.com
    ;o)
    V.V.

  • Problem with refreshing jtable. help please urgent.

    hi there
    i can refresh the table now, but the problem is that every time it refreshes, it adds the same data to the freshed table. i just need the table to display what was displayed few seconds ago unless there is change in the datasource. here is my code:
    public void run()
    String selectSQL = "select * from buyerordertable";
    int rowCounter = 1;
    boolean okay = true;
    ResultSet rs;
    Vector rowdata = new Vector();
    Vector columNames = new Vector();
    columNames.add("order Id");
    columNames.add("suplier name");
    columNames.add("item name");
    columNames.add("model");
    columNames.add("quantity");
    columNames.add("price");
    columNames.add("description");
    columNames.add("job Id");
    columNames.add("order confirm Id");
    while (okay)
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:wgclientdatabase", "admin", "");
    PreparedStatement ps = con.prepareStatement(selectSQL);
    rs = null;
    rs = ps.executeQuery();
    while(rs.next())
    Vector temp =new Vector();
    String orderid = rs.getString("OrderID");
    temp.add(orderid);
    String supplier =rs.getString("supplierName");
    temp.add(supplier);
    String item = rs.getString("ItemName");
    temp.add(item);
    String model = rs.getString("Model");
    temp.add(model);
    String quantity = rs.getString("Quantity");
    temp.add(quantity);
    String price = rs.getString("Price");
    temp.add(price);
    String description = rs.getString("Description");
    temp.add(description);
    String jobid = rs.getString("JobID");
    temp.add(jobid);
    String confirmid = rs.getString("OrderConfirmID");
    temp.add(confirmid);
    rowdata.add(temp);
    }catch (SQLException sqle)
    catch(ClassNotFoundException ce)
    try
    /*the table keeps adding old data to the refreshed table. i start with one row of data, after every second, a new row of same data is added to the table. i don't know why.*/
    DefaultTableModel newmodel =(DefaultTableModel)jTable.getModel();
    newmodel.setDataVector(rowdata, columNames);
    jScrollPane.repaint();
    Thread.sleep(1000);
    catch (InterruptedException e)
    okay = false;
    }

    hi there
    thank you for your reply
    doesn't the tablemodel keep one set of data? every time i refresh the table, the table model should only provide same data over and over unless it is reset again? in my program, the result seems like the table model is cumulating data every time it refreshes. and the display is growing with the same data. i already use the
    newmodel.setDataVector(rowdata, columNames);
    to reset the data. ideally the table should only display rowdata. some people say that just using table model will solve the refreshing task. i am not sure if they have my kind of problem.

  • 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);}

  • Refreshing JTable remotely or in another computer

    I have search the forums but i could not find the appropriate answer for my problem.
    I created a jtable with two buttons to add and delete row. This jtable and the mysql table which is the source of the data in the jtable, can be accessed by any computer on which the java program activating it, is installed. So it is possible that there could be several instances of the jtable running at the same time.
    On the computer where the add or delete button is activated, the mysql table and the jtable is updated/refreshed accordingly. There is no problem at all.
    However in the other computers where the instances of the jtable is running, the jtable is not refreshed at all. I can only refresh the jtable if I exit and restart the program.
    How can i refresh all the instances of the jtable everytime its contents are changed by any one of the computers running it?
    I have experimented using table.repaint, table.setUI, model.repaint to no avail.
    I wonder if I have to use RMI for this. Any help is very much appreciated as I have been wrestling with this problem for sometime.

    This solution by camickr works! My only problem is that it will not activate the cellrenderers and the methods to customize the columns. Thank you camickr. I hope you can help me with the cellrenderers.
    These cellrenderers work well with the original table.
    Here is the code:
    JButton Button_Refresh1 = new JButton("Refresh");
    Button_Refresh1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    Object skedData[][] = getSchedule(); //returns data from database;
    DefaultTableModel updtskedModel = new DefaultTableModel() {
    public boolean isCellEditable(int row, int column) {
    if (column == 1) {
    return false;
    } else {
    return true;
    public Class getColumnClass(int c) {
    return getValueAt(0, c).getClass();
    updtskedModel.addColumn("Date");
    updtskedModel.addColumn("Patient Name");
    updtskedModel.addColumn("Status");
    updtskedModel.addColumn("PatientNo");
    updtskedModel.addColumn("SeqNo");
    for (int i = 0; i < skedData.length; i++) {
    if (skedData[0] != null) {
    updtskedModel.addRow(new Object[]{skedData[i][1], skedData[i][2], skedData[i][3], skedData[i][0], skedData[i][4]});
    TableColumn col1 = skedTable.getColumn("Date");
    TableColumn col2 = skedTable.getColumn("Patient Name");
    TableColumn col3 = skedTable.getColumn("Status");
    TableColumn col4 = skedTable.getColumn("SeqNo");
    col1.setPreferredWidth(75); //this does not work
    col1.setCellRenderer(new DateRenderer()); // this one does not work and there are no error messages also.
    col2.setPreferredWidth(100); //this does not work
    col3.setCellEditor(new DefaultCellEditor(StatusBox)); //this one does not work and there are no error messages also
    skedTable.setModel(updtskedModel);
    //elsewhere in the code, the following class was defined.
    static class DateRenderer extends DefaultTableCellRenderer {
    public DateRenderer() { super(); }
    public void setValue(Object value) {
    setText((value == null) ? "" : regdf.format(value)); //regdf is defined elsewhere using SimpleDateFormat.

  • JTable & JDBC

    Hello all!
    I need your help! I have soon a deadline in Java Programming and I have to get the data from the MySQL Database into the jtable. The data has to be editable, so I need a TableModel, which extends AbstractTableModel. There is a perfect example of such a table in the sun tutorial, but the table is initialized in the programm (not from the database)...I can successful connect to the DB, but can not get data...Please help! Here is a programm from SunTutorial and what I do...
    public class Students extends JPanel {
    private boolean DEBUG = false;
    public Studenten() {
    super(new GridLayout(1,0));
    JTable table = new JTable(new MyTableModel());
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);
    JScrollPane scrollPane = new JScrollPane(table);
    add(scrollPane);
    class MyTableModel extends AbstractTableModel {
    private String[] columnNames = {"First Name",
    "First Name",
    "Last Name",
    "StNumber"};
    *private Object[][] data = {*
    *{"Mary", "Brown",*
    *"123456"},*
    *{"Alison", "Huml",*
    *"543212"},*
    public int getColumnCount() {
    return columnNames.length;
    public int getRowCount() {
    return data.length;
    public String getColumnName(int col) {
    return columnNames[col];
    public Object getValueAt(int row, int col) {
    return data[row][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) {
    if (DEBUG) {
    System.out.println("Setting value at " + row + "," + col
    + " to " + value
    + " (an instance of "
    + value.getClass() + ")");
    data[row][col] = value;
    fireTableCellUpdated(row, col);
    if (DEBUG) {
    System.out.println("New value of data:");
    printDebugData();
    private void printDebugData() {
    int numRows = getRowCount();
    int numCols = getColumnCount();
    for (int i=0; i < numRows; i++) {
    System.out.print(" row " + i + ":");
    for (int j=0; j < numCols; j++) {
    System.out.print(" " + data[i][j]);
    System.out.println();
    System.out.println("--------------------------");
    And that is, what I have...
    String url = "jdbc:mysql://localhost/bibliothek";
    String user = "root";
    String pass = "root";
    Connection conn = null;
    try {
    conn = DriverManager.getConnection(url, user, pass);
    Statement stmt = conn.createStatement();
    String sqlCommand ="SELECT stnumber, name, fname FROM student";
    ResultSet rs = stmt.executeQuery(sqlCommand);
    while (rs.next()) {
    String name = rs.getString(1);
    String vorname = rs.getString(2);
    String stnummer = rs.getString(3);
    System.out.println(name+" "fname" "+stnumber);
    *Object[][] data = {{name, fname, stnumber}};*
    String[] tblHead = {"Name", "FirstName", "StudentNumber"};
    JTable jTable1 = new JTable(data, tblHead);
    getContentPane().add(jTable1);
    stmt.close();
    conn.close();
    catch (SQLException sqle) {
    System.out.println("SQLException: " + sqle.getMessage());
    System.out.println("SQLState: " + sqle.getSQLState());
    System.out.println("VendorError: " + sqle.getErrorCode());
    sqle.printStackTrace();
    It dosn't work... What have I to write into Object [][] data in order to read from the database?? And in what moment have I to connect to database?? I'm waiting for your replies!!!

    Cross posted all over the place
    [http://forum.java.sun.com/thread.jspa?threadID=5310504]

  • Refreshing JTable from JTree?

    Hello everyone,
    I've created a JTable using my own table model extending AbstractTableModel...
    I'm sending data to JTable as Vector through it's constructor...
    I have also created a JTree in another class... What i intend to achieve is this:
    Whenever i click on a node of the JTree, all the childs
    of that node should be displayed in the jtable...
    I have solved part of the problem by creating a new instance of JTable whenever the tree node is clicked... obtaining the names of all the childs in a Vector and sending it to the JTable...
    The problem with this approach is that a table row is only refreshed when it's clicked upon... or if i minimize and then maximize the app...
    Please tell me how to solve this problem... if you have any other comments on the approach i've used, please share it with me...
    Thanks

    Hope the folling code snippet will help.
    jTableModel.setDataVector(rowVector,tableColumnVector);
    //get the table model and pass it in setModel() method or use the global Modal object.
    jTable.setModel(jctableModel);
    tableModelEvent=new TableModelEvent(jctableModel);
    Thanks,
    Vikas Karwal
    [email protected]

  • Refreshing JTable contents (rows and columns) handling.

    Hi,
    I have a general question related to refreshing the contents of JTable and handling some application specific requirements.In our application we are planning to refresh the contents of JTable automatically after certain period of time by fetching data from database and update the JTable contents or user has clicked refresh button.
    But following scenarios we are planning to handle when refresh is called automatically or user has clicked refresh button.
    1) User is working with data of JTable. Like rows of JTable has checkBoxes and user selects them and doing operation like viewing the details of selected rows in new details dialog. So if refreshing is done then the selection will be lost if I update the whole data in JTable.
    a)Will it be possible to append the data at the end of JTable rows without disturbing the existing JTable contents.
    b) Is it feasible to compare the data of existing rows and newly fetched rows and update only the rows whose values are changed in database or update specifically updated columns. But this comparision for finding changed values will result in performance problems.So are there any other alternatives of doing this, ideas are most welcome.
    c) Simple way is to alert the user that data will be updated and everything will be refreshed will be the choice in worst case.
    I guess many may have encountered such problems and may have solved it depending on the product requirements.
    Ideas and suggestions are most welcome.
    Regards.

    Hi,
    Here are my views and my assumptions.
    Assumptions :
    1) Your JTable is populated with list of Objects.
    2) Your tables in database is having columns like created date, created time, updated date updated time
    3) Order by clause for all the time will remain same.
    If these assumptions are correct then I think you can achieve your goal.
    Here how it is.
    Your application session will maintain last db hit time and will maintain for every hit that applicate made to fetch data from db.
    When object is created on the server side once it fetch data from table it will compare the created date/time or update date/time with the session varibale that holds last visit date/time. Based on this flag need to be set to indicate if this item is added/updated/deleted since last visit.
    And when all these object is returned to your client, the table model will iterate through the list and based on object index in the list and and if object is changed will update only that perticular row.
    Hope this is what you want to achieve.
    Regards

  • Refresh jTable after inserting new data into the Database

    Hey all,
    I'm using Netbeans 6.5 to create a Desktop Application which is connected to a Java DB (Derby).
    The first simple steps were all very successfull:
    Create the jTable and bind it to the Database => everything works fine. When the application starts it correctly shows all data from the database.
    The problem starts when I try to insert new data to the database.
    For that reason I've created textfields and a button "Save". When I press the button it successfully inserts the data to the database but they are not displayed in the jTable (when the application starts they are all there, they are not updated at runtime) . I've tried table.invalidate() and table.repaint() but they just don't work.
    Any help will be GREATLY appreciated. But please have in mind that most of the code is Netbeans-generated and most of it not editable.
    Many thanks in advance.
    George

    Once again you are right my friend. I jumped to conclusion way too fast, when I shouldn't. (Give me a break, I've been busting my head with this well over a week). The response I saw when I did that was that indeed a line is added to the jTable. Because I falsly set the index of the object to be added to be second to last the row appeared on the table, what I didn't see at the time was that the last one disappeared. Hmm...
    A new adventure begins...
    So after a few hours of messing around with it here are my observations:
    1) It was not an observable list. When I add the new element with employeesList.add(newEmp); , the table gets notified but a get a bunch of exceptions:
    xception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 84, Size: 84
            at java.util.ArrayList.RangeCheck(ArrayList.java:546)
            at java.util.ArrayList.get(ArrayList.java:321)
            at org.jdesktop.swingbinding.impl.ListBindingManager$ColumnDescriptionManager.validateBinding(ListBindingManager.java:191)
            at org.jdesktop.swingbinding.impl.ListBindingManager.valueAt(ListBindingManager.java:99)
            at org.jdesktop.swingbinding.JTableBinding$BindingTableModel.getValueAt(JTableBinding.java:713)
            at javax.swing.JTable.getValueAt(JTable.java:1903)
            at javax.swing.JTable.prepareRenderer(JTable.java:3911)
            at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2072)
            at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1974)
            at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1897)
            at javax.swing.plaf.ComponentUI.update(ComponentUI.java:154)
            at javax.swing.JComponent.paintComponent(JComponent.java:743)
            at javax.swing.JComponent.paint(JComponent.java:1006)
            at javax.swing.JViewport.blitDoubleBuffered(JViewport.java:1602)
            at javax.swing.JViewport.windowBlitPaint(JViewport.java:1568)
            at javax.swing.JViewport.setViewPosition(JViewport.java:1098)
            at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.vsbStateChanged(BasicScrollPaneUI.java:818)
            at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.stateChanged(BasicScrollPaneUI.java:807)
            at javax.swing.DefaultBoundedRangeModel.fireStateChanged(DefaultBoundedRangeModel.java:348)
            at javax.swing.DefaultBoundedRangeModel.setRangeProperties(DefaultBoundedRangeModel.java:285)
            at javax.swing.DefaultBoundedRangeModel.setValue(DefaultBoundedRangeModel.java:151)
            at javax.swing.JScrollBar.setValue(JScrollBar.java:441)
            at javax.swing.plaf.basic.BasicScrollBarUI.scrollByUnits(BasicScrollBarUI.java:907)
            at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.mouseWheelMoved(BasicScrollPaneUI.java:778)
            at javax.swing.plaf.basic.BasicScrollPaneUI$MouseWheelHandler.mouseWheelMoved(BasicScrollPaneUI.java:449)
            at apple.laf.CUIAquaScrollPane$XYMouseWheelHandler.mouseWheelMoved(CUIAquaScrollPane.java:38)
            at java.awt.Component.processMouseWheelEvent(Component.java:5690)
            at java.awt.Component.processEvent(Component.java:5374)
            at java.awt.Container.processEvent(Container.java:2010)
            at java.awt.Component.dispatchEventImpl(Component.java:4068)
            at java.awt.Container.dispatchEventImpl(Container.java:2068)
            at java.awt.Component.dispatchMouseWheelToAncestor(Component.java:4211)
            at java.awt.Component.dispatchEventImpl(Component.java:3955)
            at java.awt.Container.dispatchEventImpl(Container.java:2068)
            at java.awt.Component.dispatchEvent(Component.java:3903)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3965)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
            at java.awt.Container.dispatchEventImpl(Container.java:2054)
            at java.awt.Window.dispatchEventImpl(Window.java:1801)
            at java.awt.Component.dispatchEvent(Component.java:3903)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
    Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 84, Size: 84
            at java.util.ArrayList.RangeCheck(ArrayList.java:546)
            at java.util.ArrayList.get(ArrayList.java:321)
            at org.jdesktop.swingbinding.impl.ListBindingManager$ColumnDescriptionManager.validateBinding(ListBindingManager.java:191)
            at org.jdesktop.swingbinding.impl.ListBindingManager.valueAt(ListBindingManager.java:99)
            at org.jdesktop.swingbinding.JTableBinding$BindingTableModel.getValueAt(JTableBinding.java:713)
            at javax.swing.JTable.getValueAt(JTable.java:1903)
            at javax.swing.JTable.prepareRenderer(JTable.java:3911)
            at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2072)
    ... and a lot morewhich from my poor understanding means that the jTable succesfully notices the change but it is not able (??) to adjust to the new change. What is more interesting is that when I plainly add the element to the end of the list (without an idex that is), a blank row appears at the end of my Table. The weird thing is that I've bound the table to some text fields below it, and when I select that empty row all the data appear correctly to the text fields.
    I tried going through:
                    org.jdesktop.observablecollections.ObservableCollections.observableList(employeesList).add(newEmp);as well as
                    help = org.jdesktop.observablecollections.ObservableCollections.observableListHelper(employeesList);
                    help.getObservableList().add(newEmp);
                    help.fireElementChanged(employeesList.lastIndexOf(newEmp));and
                    obsemployeesList = org.jdesktop.observablecollections.ObservableCollections.observableList(employeesList);
                    obsemployeesList.add(newEmp);and I still get the same results (both the exeptions and the mysterious empty row at the end of the table
    So, I'm again in terrible need of your advice. I can't thank you enough for the effort you put into this.
    Best regards,
    George
    Edited by: tougeo on May 30, 2009 11:06 AM
    Edited by: tougeo on May 30, 2009 11:21 AM
    Edited by: tougeo on May 30, 2009 11:30 AM

  • Refreshing JTable Contents Correctly

    I am using a JTable within a JScrollPane. The porblem I am having is getting the JTable to redisplay correctly when the TableModel data changes.
    I tried creating a new instance of TableModel each time I update data to be displayed, and (re)setting the JTable's model to the new instance. this displays the data correctly. (Any of the fixed viewport space that is not occupied is gray.) Unfortunately with this strategy, each time the JTable is updated, the scrollbar position changes (sometimes overlapping the data, sometimes outside the data) or if no scrollbar is needed, blank space appears whenever the previous display had a scrollbar.
    The second strategy I tried was clearing the values in the SAME TableModel (no new instance) and loading the new data into it. This works, except that when a new set of data is displayed, if the previous display had more rows displayable, white space fills the now vacant space. I tried revalidating the table, but that throws an array-out-of-bounds exception at the model's "getValueAt(r,c)" method.
    Can someone tell me the correct strategy for loading new data into a JTable, and get the data to re-display correctly?
    Thanks for your help.

    You don't have to create a new instance every time. To redisplay the whole data, just get the current Table Model say tableModel and set row count to 0 like tableModel.setRowCount(0). Now add all the rows into the model.
    Also sometime getAutoCreateColumnsFromModel() when set to true gives problems when you define your own TableColumn's. So you have to set it to false.
    I will suggest using the TableColumnModel along with TableModel for a table. (For advanced development it helps)
    It should display correctly. You can fine tune the table with lot of properties available for table. You have to read doc for the same.
    Hope it helps.

  • JTable and JFrame

    1) How do I call a JOptionPane dialog when I click the table header?
    2) I hv 2 JFrames. The 1st one has a JTable. When I want to insert some record, this JFrame will call another JFrame (Class2). I would like to refresh JTable (1st Class) after closing Class2. Is this possible?
    Thanks.

    1. Check out the tutorials
    2. For header clicking, you may need some sort of event enabling logic. It's probably not too simple
    3. For closing a window check out java.awt.event.WindowAdapter

  • JTable - Is this possible?

    I hv 2 JFrames. The 1st one has a JTable. When I want to insert some record, this JFrame will call another JFrame (Class2). I would like to refresh JTable (1st Class) after closing Class2. Is this possible?
    Thanks

    secondWindow.addWindowListener(new WindowAdapter(){
      public void windowClosing(WindowEvent e){
        //firstWindow.table.refresh();
    });

  • Messages waiting in the queue for long time.

    Hi Experts,
    We are having some Production issue - messages were waiting in the queue for long time and we found the errors in defaultTrace.12.trc file -
    Please help how to solve this issue its production and we need to move forward and solve this issue asap.
    XI AF API call failed. Module exception: (No information available). Cause Ex
    ception: 'JDBC Adapter configuration not initialized: null'.
    Thrown:
    com.sap.aii.af.service.api.AFException: XI AF API call failed. Module exception: (No information available). Cause Exception: 'JDBC Adapter configuration not
    initialized: null'.
            at com.sap.aii.af.service.api.AdapterAccess.sendMsg(AdapterAccess.java:214)
            at com.sap.aii.af.service.api.AdapterAccess.call(AdapterAccess.java:99)
            at com.sap.aii.ibrun.server.lookup.AdapterProxyLocal.process(AdapterProxyLocal.java:87)
            at com.sap.aii.ibrun.server.lookup.SystemAccessorInternal.call(SystemAccessorInternal.java:47)
            at com.sap.aii.mapping.lookup.SystemAccessor.call(SystemAccessor.java:115)
            at com.sony.pi.sp.StoredProceduresHandler.runScalarStoredProcedure(StoredProceduresHandler.java:86)
            at com.sap.xi.tf._MyPage_Invoice_SAP_to_Loyalty_MM_.invokePROC_CUSTOMER_DEDUP$(_MyPage_Invoice_SAP_to_Loyalty_MM_.java:1272)
            at sun.reflect.GeneratedMethodAccessor384.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at com.sap.aii.mappingtool.tf3.rt.C2CFunctionWrapper.cacheContext(C2CFunctionWrapper.java:91)
            at com.sap.aii.mappingtool.tf3.rt.C2CFunctionWrapper.gotoNextContext(C2CFunctionWrapper.java:44)
            at com.sap.aii.mappingtool.tf3.rt.Q2QFunctionWrapper.cacheQueue(Q2QFunctionWrapper.java:86)
            at com.sap.aii.mappingtool.tf3.rt.Q2QFunctionWrapper.gotoNextContext(Q2QFunctionWrapper.java:41)
            at com.sap.aii.mappingtool.tf3.rt.Q2QFunctionWrapper.cacheQueue(Q2QFunctionWrapper.java:74)
            at com.sap.aii.mappingtool.tf3.rt.Q2QFunctionWrapper.gotoNextContext(Q2QFunctionWrapper.java:41)
            at com.sap.aii.mappingtool.flib3.CollapseContexts.gotoNextValue(CollapseContexts.java:52)
            at com.sap.aii.mappingtool.flib3.CollapseContexts.gotoNextContext(CollapseContexts.java:37)
            at com.sap.aii.mappingtool.tf3.rt.AResIterator.gotoNextContext(AResIterator.java:37)
            at com.sap.aii.mappingtool.tf3.rt.FunctionWrapper.gotoNextContext(FunctionWrapper.java:37)
            at com.sap.aii.mappingtool.flib3.IfWithoutElse.gotoNextContext(IfWithoutElse.java:58)
            at com.sap.aii.mappingtool.tf3.AMappingProgram.processNode(AMappingProgram.java:266)
            at com.sap.aii.mappingtool.tf3.AMappingProgram.processNode(AMappingProgram.java:326)
            at com.sap.aii.mappingtool.tf3.AMappingProgram.processNode(AMappingProgram.java:326)
            at com.sap.aii.mappingtool.tf3.AMappingProgram.start(AMappingProgram.java:415)
            at com.sap.aii.mappingtool.tf3.Transformer.start(Transformer.java:142)
            at com.sap.aii.mappingtool.tf3.AMappingProgram.execute(AMappingProgram.java:118)
            at com.sap.aii.ibrun.server.mapping.JavaMapping.executeStep(JavaMapping.java:64)
            at com.sap.aii.ibrun.server.mapping.Mapping.execute(Mapping.java:92)
            at com.sap.aii.ibrun.server.mapping.MappingHandler.run(MappingHandler.java:90)
            at com.sap.aii.ibrun.sbeans.mapping.MappingRequestHandler.handleMappingRequest(MappingRequestHandler.java:95)
            at com.sap.aii.ibrun.sbeans.mapping.MappingRequestHandler.handleRequest(MappingRequestHandler.java:68)

    Hi All,
    CPACache refresh worked for one day and the same problem repeated again next day, but need to have parmanent fix and should know the root cause of the problem so that the problem can not be repeated again.
    Is there any solution other than  CPACache refresh and JDBC adapter stop and start to fix the issue.
    And also found some entries in SM12 lock entry list during the same schedule time when the messages was triggered and remains for long time. Let me know whether we can delete those locks ?
    user PIAFUSER
    Lock mode E
    and table SXMSPMAST
    with lock argument ......
    Any suggestions and tips help us alot in fixing this issue.
    Thanks in advance
    Gary.

  • SAP Dataservices with MYSQL

    Hello there
    I am having a problem trying to install DS. I have installed MySQL and set the Classpath to  the location of the file mysql-connector-java-5.1.30-bin.jar. I was having issues with JDBC driver which picked from browse screen to the same file. Then I get the error in the screenshot.
    Invalid JDBC driver, please check driver path. Am In missing something?
    Any step by step guide ?
    Appreciate help on this.
    Thanks
    Anand

    Hi Anand,
    Download the JDBC driver for your database to a location on the Data Services host system.
    Copy the JDBC driver to all locations required by Data Services.
    For Oracle and MySQL databases:
    <LINK_DIR>\ext\lib
    <BIP_INSTALL_DIR>\java\lib\im\<database_type>
    database_type is mysql for MySQL, and oracle for Oracle.
    <BIP_INSTALL_DIR>\warfiles\webapps\DataServices\WEB-INF\lib
    Refresh the JDBC configuration.
    Also refer the installation guide for DS for further reference.
    http://help.sap.com/businessobject/product_guides/sboDS41/en/sbo411_ds_install_win_en.pdf
    Regards,
    Karthik

  • 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,

Maybe you are looking for