How to dynamically update JTable

My application gets results from database as a set of resultsets. I display these results in a table. But generally stored procedure used used takes alot of time to get the full set of result sets. So this at times is annoying for user to wait for all the result when it could be much better if i could display results as and when recieved. For this i add the data recieved to the data vector and then call fireTableRowsInserted() on its model. which should update its view but this does not happen. Can someone advise me on how to achieve this.
greetings.

Your table model should extend AbstractTableModel. And when (for example) it adds a row to whatever data structure is supporting the model, it should call fireTableRowsInserted... you can find out more about those methods in the API documentation. You don't need to revalidate or invalidate or validate the JTable, at least I don't have that in my code anywhere.

Similar Messages

  • How to auto update JTable during runtime

    Can anyone tell me how to dynamically update a JTable during execution, what i mean isin the I want the table to automatically add new rows as i enter new data.
    if I pass the object array reference of the TableModel to a method, then add more objects to the array and the revalidate the JTable will it work, or how do I do it ? Thanks

    Your table model should extend AbstractTableModel. And when (for example) it adds a row to whatever data structure is supporting the model, it should call fireTableRowsInserted... you can find out more about those methods in the API documentation. You don't need to revalidate or invalidate or validate the JTable, at least I don't have that in my code anywhere.

  • How to dynamically update columns in a where clause to a SQL query in OSB?

    Hi Gurus,
    I have a requirement where in we need to dynamically update a where clause to a SQL query in OSB(11.1.1.6.0).
    For example:
    If the JCA sql string is "select * from emp where emp_id = 100 and emp_status ='Permanent'" now i want to change this where clause and the new query has to be like "select * from emp where emp_name like 'S%' and emp_dept like 'IT' ". basically we need to change the where clause dynamically.
    We can also use "fn-bea:execute-sql()" in a xquery but I don't want to use this function as creates a new connection.
    I have done some home work and found out --> as per the DOC "http://docs.oracle.com/cd/E23943_01/dev.1111/e15866/jca.htm#OSBDV943" section: "25.5.2 JCA Transport Configuration for Proxy and Business Services", when a business service is created by using JCA, we can see Interaction Spec Properties under JCA Transport Tab. This will have a property "SqlString' and we can over ride it. But I am unable to figure out how to over ride the value. I have tried by using Transport Headers activity but no luck. Please guide me how to achieve this?
    Thanks in advance
    Surya

    I solved my problem.
    In my header renderer, I simply added a line to set the text to the object value "label.setText( (String) value );" (where label is an instance of a JLabel.
    Thank you to who took some time to think about it.
    Marc

  • Dynamically Updating JTable, please help

    I am trying to create an GUI for a java program I wrote to interface with motes running TinyOS. I am having some serious problems creating this because in the JTable tutorial everything is static so I can't figure out how I'm supposed to modify the table from my code. I'm basically reading packets coming in from the serial port and updating several data fields based on what is contained in the packet. I want certain cells in the JTable to reflect the changes that occur in the variables I have, sort of like a debugger would display, but in real time and at full run speed. I tried using the setValueAt function but the problem is the JTable is created in a static method and so I cannot call it from main. I tried moving the section of code that monitors the serial port and updates my data to the createAndShowGUI function, but unfortunately the table will not display unless this function returns, but the program will never return from this function if I move the code there and so I just get a completely grey JTable displayed. I have included the code below, sorry for the length of it but I need some help on this one, I was never taught java and am trying to learn this on my own for research purposes. As it stands now the only error generated by this code is from the following line:
    newContentPane.DataTable.setValueAt("asdfsa",1,1);
    I am not allowed access to newContentPane because it has been dynamically instantiated by createAndShowGUI and I cannot access it through main.
    I'd appreciate any help on this, thank you.
    package net.tinyos.tools;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JComponent;
    import javax.swing.ListSelectionModel;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.util.Date;
    import java.io.*;
    import net.tinyos.packet.*;
    import net.tinyos.util.*;
    import net.tinyos.message.*;
    public class BeaconListen extends JPanel {
    private static int MAX_NODES = 10;
         JTable DataTable;
         public BeaconListen(){
         super(new GridLayout(1,0));     
         Object[] ColumnNames = {"Node","PPS","Average PPS","Time Elapsed"};
         Object[][] Data= {
         {"0","","",""},
         {"1","","",""},
         {"2","","",""},
         {"3","","",""},
         {"4","","",""},
         {"5","","",""},
         {"6","","",""},
         {"7","","",""},
         {"8","","",""},
         {"9","","",""},
         DataTable = new JTable(Data,ColumnNames);
         DataTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
         JScrollPane scrollPane = new JScrollPane(DataTable);
    add(scrollPane);
    * Create the GUI and show it. For thread safety,
    * this method should be invoked from the
    * event-dispatching thread.
    private static void createAndShowGUI(){
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Create and set up the window.
    JFrame frame = new JFrame("MoteData");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Create and set up the content pane.
    BeaconListen newContentPane = new BeaconListen();
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.setContentPane(newContentPane);
    //Display the window.
    frame.pack();
    frame.setVisible(true);
         if (args.length > 0) {
         System.err.println("usage: java net.tinyos.tools.BeaconListen");
         System.exit(2);
         public static void main(String args[]) {
         //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
                   PacketSource reader = BuildSource.makePacketSource();
         if (reader == null) {
         System.err.println("Invalid packet source (check your MOTECOM environment variable)");
         System.exit(2);
              int i, total = 0;
         int reset =1;
         int packetcount[] = new int[MAX_NODES];
         int PL[] = new int[MAX_NODES];
         int counter[] = new int[MAX_NODES];
         double RSSI[]= new double[MAX_NODES];
         int signalStrength=0;
         double strengthUnsigned=0;
         int Transition=0;
         int PPS=0;
         int FirstRun=1;
         int packetHold=0;
         double avgPacketCount[] = new double[MAX_NODES];
         int secondsElapsed=0;
         int averageReset=1;
         int totalPacketsReceived[] = new int[MAX_NODES];
         System.out.println("Node Listening");
         try {
         reader.open(PrintStreamMessenger.err);
         for(;;){
              byte[] packet = reader.readPacket();
         if(reset==1)
         for(i=0; i<MAX_NODES; i++)
              packetcount=0;
              PL[i]=0;
              counter[i]=0;     
              if(averageReset==1)
              secondsElapsed=0;
              avgPacketCount[i]=0;
              totalPacketsReceived[i]=0;
         reset =0;
         if(FirstRun==0)
         packetcount[packetHold]++;
         totalPacketsReceived[packetHold]++;
         PPS++;
         FirstRun=0;
         averageReset=0;
         packetcount[packet[6]]++;
         totalPacketsReceived[packet[6]]++;
         PPS++;
         strengthUnsigned = ((int)packet[8])& 0xFF;
         RSSI[packet[6]]=RSSI[packet[6]]+strengthUnsigned;
    if((packet[10]==1 && Transition==1) || (packet[10]==0 && Transition==0))
         secondsElapsed++;
         if(Transition==1)
         Transition=0;
         else
         Transition=1;
         PPS--;
         packetcount[packet[6]]--;
         totalPacketsReceived[packet[6]]--;
         packetHold=packet[6];
         reset=1;
         for(i=0; i<MAX_NODES; i++)
         newContentPane.DataTable.setValueAt("asdfsa",1,1);
              System.out.println("Packet Count for Node " + i + "is: " + packetcount[i]);
              PL[i]=8 - packetcount[i];
              System.out.println("Packet Loss for Node " + i + "is: " + PL[i]);
              avgPacketCount[i]=1.0*totalPacketsReceived[i]/secondsElapsed;
              System.out.println("Avg Packet Count for " + secondsElapsed + " seconds is: " +avgPacketCount[i]);
              if(RSSI[i]!=0)
              RSSI[i]=RSSI[i]/packetcount[i];
              RSSI[i]=3*(RSSI[i]/1024);
              RSSI[i]=(-51.3*RSSI[i])-49.2;
              System.out.println("RSSI(dBm) for node " + i + "is: " + RSSI[i]);
              System.out.println();
              packetcount[i]=0;
              RSSI[i]=0;
         System.out.println("Total Packets Recieved: " + PPS);
         PPS=0;
                   System.out.println();
                   System.out.println();
         javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
         catch (IOException e) {
         System.err.println("Error on " + reader.getName() + ": " + e);

    The best way to update your data is using a TableModel :
    When you instantiate a JTable with an array of objects, it creates a DefaultTableModel which actualy stores your data.
    So, you should create your TableModel, and feed it with the data. Each time the data is updated, the TableModel must notify the JTable, so the new data can be shown :
    here's a simple example
    public class MyModel extends AbstractTableModel
    Object[][] data;
    //you must implement some abstract methods declared in AbstractTableModel
    //the method you use to update the data (you can give it the name you want)
    setData(Object[][] _data)
    data=_data;
    fireTableDataChanged();//method of AbstractTableModel that notifies the data has changed
    public void main(String[] s)
    MyModel tableModel = new MyModel();
    JTable table = new JTable(tableModel);
    JFrame frame = new JFrame();
    frame.getContentPane().add((new JScrollPane()).getViewport().add(table);
    frame.pack();
    frame.setVisible(true);
    tableModel.setData(new Object[][]{{"one", "two"}, {"three", "four"};
    thread.sleep(5000);
    tableModel.setData(new Object[][]{{"five", "six"}, {"seven", "eight};
    You will see the table displaying one, two, three, four, during 5 seconds, and then it will display five, six...

  • How to dynamically update the Table?

    Hi All,
    Hope somebody will help me out ot resolve my issue.
    In my application, about 10 analog channels data coming in. Out of which two parameter needs to get updated dynamically on the table. (For each Rpm between 500-1000, in steps of 50, have to capture Pressure points & show it on the table.)
    I seen there is one method called table method available which helps to set the value of a particular cell specified by corresponding row and column index.
    I tried this. In row 0, col 0 & col 1 it put what value I specified by using that table method. when it goes to row 1, col 0 & col 1 also got updated but vanishing the above put row 0, col 0 & col 1 values. so at any point of time, I am able to see only the current row values.
    Hope there should be some dynamic refreshing method available or else I dont know how to handle this situation. Pls. clarify.
    Thanks,
    Kousy

    Hi,
    Thanks.
    But I am not able to update dynamically.
    I just done slight changes to your update.vi. Just run Update_1.vi and after update
    button is pressed, change the row, col index to see the update. please note
    it is not able to update if matrix exceeds 3x4. i.e set row index=3
    col index=0; new cell value = 10. it is not updating.. it might because of initialization
    of 3x4 matrix values at the start.. ot the way I am trying out is bad?
    By using Table method itself I got the solution what I want. I have attached that vi too.
    just check out and reply if any flaw..
    Thanks,
    Kousy
    Attachments:
    update_1.vi ‏94 KB
    Table Update.vi ‏96 KB

  • How to force update jtable display

    I am trying to add some filtering funtionality to my swing application that uses a JTable. What I do is to filter the JTable's datamodel, and call repaint() on the jtable and JPanel, and do jframe.pack(); Sometimes it works, sometimes it doesn't. I check the jtable model, and it is being updated properly. I guess it is a GUI update problem. Is there a better way to force the whole app's GUI to be updated?
    //update tableModel
    //repaint() jtable;
    //repaint() jpanel;
    jf.pack();

    A couple questions
    1. Did you write your own table model? Not calling fireTableDataChanged() can cause problems in this case.
    2. Do you update the table from a thread? You might need to put the updates on the event thread (SwingUtilities.invokeNoow() or invokeLater()) or manually call fireTableDataChanged() (I'm not sure if this needs to happen on the event thread)

  • How can I update JTable with new Object[][]

    Hallo, I have got a problem. I want to update my Jtable with new Values,
    with
    setValueAt(Object aValue, int row, int column)
    i can only update one Object.
    Is it possible to update All Objects "Object[][]"??? in a whole Table
    after I clicked a Button???

    Hi,
    AbstractTableModel's method setValueAt(Object aValue, int row, int column)
    is not the way to fill values into a table. It is the way the table returns the changed values to you after the user has entered something. This is a very common misconception, probably because the method names are so confusing.
    The table model uses getValueAt (int row , int column)
    to fill in its rows and columns.
    If you extend AbstractTableModel to make this method fill in the correct values from you data array. then, when you wish to update the whole table, you can
    1) Put new values in the data array
    2) fireTableValuesChanged
    this will cause the table model to call getValueAt for every row and column.
    good luck.

  • How can i dynamically update a table in my program?

    Hi there!
    I would like to know if anyone can assist me with advice on how to dynamically update
    a table within my program, with new values from the database?
    Thanking You all.

    Add rows to its model.
    Kind regards,
    Levi

  • How to generate a dynamic update query to update error flag in a mapping?

    i have a mapping in which i m loading log table through generated parameter file.But i want to update the error flag using dynamic update query.for that i have to generate a query and use update sqloverridw in target instances.but i m not getting how to implement it.Please help..!!

    Hi  All, I have a scenario. Below is the source record. field1|field2|field3|field4|field5|field6|field7
    5|20150329|1|980100001|500|My name is Lalita|25
    5|20150329|1|303444442|200|My name is |Lalita.I work in TCS|26
    5|20150329|1|442101001|1000|My name is Lalita.I worked Syntel|56
    5|20150329|1|446788900|300|My name|67  My source file is | separator. But for field6 the data might come with '|'.
    So I want to import the data along with '|' after separating all field in Informatica Layer.  Source team is not going to preformat the file. Please suggest how to achive this.

  • How can i update data in JTable at run time ?

    i am trying to build a client/server architecture for conducting quizzes & online tests.. My client will return a object to the server after the test is over, which contains details about the participant, his score and other details. i am putting the incoming object to an Vector. I'll create a new thread each time for the incoming connection and insert the object to the Vector.. Now, please tell me tat, how can i update my table automatically at run time so tat, my table is updated whenever a new object is entered into vector..
    here is my code for the table..
    public class MyTableModel extends AbstractTableModel {
        String columNames[] = { "ID", "NAME", "COLLEGE", "SCORE", "CELL" };
        /** Creates a new instance of MyTableModel */
        public MyTableModel() {
            Main.List = new Vector();
            SetDefaultData();
        public int getRowCount() {
            return Main.List == null ? 0 : Main.List.size();
        public int getColumnCount() {
            return columNames.length;
        public String getColumnName(int column) {
            return columNames[column];
        public boolean isCellEditable(int row,int col) {
            return false;
        public Object getValueAt(int rowindex, int columnindex) {
            if(rowindex < 0 || rowindex >= getRowCount())
                return "";
            Student row = (Student)Main.List.elementAt(rowindex);
            switch (columnindex)
                case 0 : return row.id;
                case 1 : return row.name;
                case 2 : return row.college;
                case 3 : return row.score;
                case 4 : return row.cell;
            return "";
        public String getTitle() {
            return "Student Table";
        private void SetDefaultData() {
            Main.List.removeAllElements();
            Main.List.addElement(new Student("CS041","Keerthivasan M","MNM",95,"9884326321"));
            Main.List.addElement(new Student("CS012","Arun M","MNM",90,"9884825780"));
            Main.List.addElement(new Student("CS019","Balaji S","MNM",79,"9841742068"));
            Main.List.addElement(new Student("CS005","Anand R","MNM",89,"9884130727"));
            Main.List.addElement(new Student("CS045","Manish J","MNM",55,"9841624625"));
            Main.List.addElement(new Student("CS013","Mangal S","MNM",5,"9841961742"));
    }

    In the future Swing related questions should be posted in the Swing forum.
    how can i update my table automatically at run time so tat, my table is
    updated whenever a new object is entered into vector..You don't update the Vector directly. You should be creating a method in your TableModel, called "addRow(...)". This method will do two things:
    a) add the Student object to the Vector
    b) invoke the fireTableRowsInserted(..) method of AbstractTableModel. This will cause the table to be repainted.

  • Dynamic update of safety stock in SAP R/3 systems (ECC 5.0 version)

    Hi Friends,
    Forgive my newness to SAP. Let me explain the problem i am facing in SAP. I want to identify the parameters to dynamically update the finished goods safety stock for each depot by SKU wise.
    Current process :- Safety stock is calculated manually and updated by using Transaction code MS02 in the system.
    It would be highly useful if i know the flow in SAP system and how the current process can be changed?
    If more info is required i'm ready to give.
    Thanks in advance

    Hi Mario Adler,
    Thanks a ton for ur answer.
    Will it update safety stock for finished goods in each depot by SKU wise? Raw material safety stock isn't my concern.
    project description :  Manufacturer of chemical goods , 70+ products,350 skus
    Distribution : factory to depot (bulk volume)
                          Mother go-down to depot(Stock transfer)
                         No of depots :33,factory:3,mother go-down -1
    Sales forecasting is done in excel for every month and updated to SAP via  BAPI. After that DRP,MRP and other runs takes place.
    What are all the areas i need to touch in to get the parameters to update the safety stock?
    Regards
    Arasu
    Edited by: Arasu_IIM on Apr 26, 2011 12:52 PM

  • Please help! Ipod not dynamically updating smart playlists!

    I have quite a complex system of smart playlists on my 4G color ipod but I can't get any of them to update dynamically away from the computer. I have a total of 6 and here are their preferences:
    SPL 1:
    match ALL
    1) My rating is in the range 4-5 stars
    2) Last played is not in the last 1 day
    3) Last skipped is not in the last 1 day
    4) Playcount is less than 5
    limit to 100 by most recently added
    SPL 2:
    match ALL
    1) My rating is in the range 0-3 stars
    2) Last played is not in the last 1 day
    3) Last skipped is not in the last 1 day
    4) Playcount is less than 4
    limit to 55 songs by most recently added
    SPL 3:
    match ALL
    1) My rating is in the range 3-5 stars
    2) Last played is not in the last 1 day
    3) Last skipped is not in the last 1 day
    4) Playcount is greater than 5
    limit to 30 songs by random
    SPL 4:
    match ALL
    1) Last played is not in the last 1 day
    2, 3, 4) Playlist is not SPL 1, SPL 2, or SPL 3
    limit to 15 songs by random
    Unwanted:
    match ANY
    1) Time is greater than 15 minutes
    2) Genre is Comedy
    The active playlist that I use to listen to:
    match ANY
    1-4) Playlist is SPL 1, SPL 2, SPL 3, or SPL 4
    5) Playlist is not Unwanted
    So here's the problem. When I sync with my computer, the playlists work great, everything updates as expected and I get a pretty diverse playlist every time I sync which I want. The problem is that while I'm listening to my music on the ipod away from the computer, my playlists don't dynamically update. After I listen to a song, the song's supposed to remove itself from the playlist which doesn't happen, as well as when I skip songs. Even when I rate songs that aren't rated they don't appear in any playlist. This is really frustrating and I can't find a solution anywhere and yes, I do have Live Updating selected. I also have "Match only checked items" selected on all playlists as well. If anyone has any ideas for how to fix this, I would love to know. Thanks!

    I was searching this forum and found someone who says that 4th gen ipods have problems live updating smart playlists if the criteria "last skipped" is on the playlist. I took this off of all of my playlists but they still don't work. Then I tried making a playlist that is just "rating is equal to 5 stars" and it WORKS!!! But that doesn't help me out much for my other playlists so maybe it's some other criteria that's causing the problem. Any ideas?

  • Update JTable from String[][]

    Hello everyone, I have a JTable with a slightly customized DefaultTableModel shown below:
    DefaultTableModel tableModel = new DefaultTableModel(rowData, columnNames){
         private static final long serialVersionUID = 8655602888381735851L;
         @Override
             public boolean isCellEditable(int row, int column)
                         return false;
              };rowData is a String[][] of my data. When a user clicks a button, they add a row of data to the String[][]. I am wondering how I can update the JTable to reflect this change in the String[][]. Thanks!

    The problem with that is that I'm going to be performing various searches through the data, and those searches are performed on a TreeMap.
    rowData gets its data from the TreeMap, and is then displayedThe active verb does not describe the situation accurately: according to your code, rowdata is merely built from the TreeMap instance, and stuffed into a DefaultTableModel for display.
    When the user adds data, they add it to the TreeMap so that it can be searched.
    I can easily convert the data from the TreeMap to the String[][], but I don't know how to "redraw" the table with the new data.I assume the data is too big to repeat the process each time the user adds a row (build the new String[][], wrap it into a new DefaultTableModel instance and set the instance as the table's model).
    Another way is to duplicate the structure: when the user adds a row, add it into the searchable collection, and into the table model. But this costs twice the memory, and, again, I assume your data set is too large.
    A third, probably more elegant way is to build your own TableModel implementation: it could store a reference to the TreeMap instance, and an array converting the table's row index values to the tree's key value. That way the table model can be described in the active mode:
    "the JTable asks the model for cell values, and the model asks the tree for the corresponding data" :o)

  • Update Jtable from access database

    as the title suggests help me guys... till now i have a database and some contents in it.. when the application starts the table is filled with contents of the database.. now whenever i add or remove a row in the databse i want to show it in the table... i have a Vector called dbData with the present contents of the database.. i want to update jtable with contents of dbData.... how to do it??

    the best things i can see to do is
    JTable table = new Jtable(.....); // this was ur table before;
    deleteRow(table); // you deleted the row
    // now you have a vector containing all the data for the rows;
    // but you need a vector containing the columns for the rows too
    //so now you do
    table = new JTable(dbData,columnnames);
    repaint();dbData must be a vector of vectors;
    dbData.elementAt(1) return a vector with all the data for row one
    so dbData.elementAt(1).elementAt(1) will be the data for row 1 column 1
    // dbData will be the data still remaining in the table
    or instead of the above you could use a nested for loop and set each element one at a time
    Object temp;
    int numberofRows = dbData.elementCount();
    int numberofColumns = db.elementAt(0).elementCount();
    for(int row = 0; row < numberofColumns;row++)
    for( int column = 0; column < numberofRows; column++)
      temp = dbData.elementAt(row).elementAt(column);
      table.setValueAt(temp,row,column);
    }

  • Stop dynamic updating of ldap from radius

    We use iPlanet v.4.12 ldap server with radius extensions. At some point in time we have started dynamic updating of the ldap server with session information from the radius server and now I can't find out how to turn off this dynamic updating. I have removed the check mark beside Dynamic accounting in the console configuration page for the radius server, but am still getting the following error messages by the thousand
    [18/Dec/2002:17:39:13 +0100] - add value for type dynamicipaddress failed: duplicate value
    [18/Dec/2002:17:39:13 +0100] - add value for type dynamicsessionid failed: duplicate value
    Can anyone give me a detailed method of turning off this feature please.
    TIA
    James

    Solved this.
    When you turn off dynamic accounting in the console, the schema is changed from Dynamic=yes to Dynamic=false. I went in and manually adjusted the schema to Dynamic=no and dynamic accounting was finally turned off.
    Just in case anyone else has the same problem.
    mvh/regards
    James

Maybe you are looking for

  • Oracle compatibility with windows vista

    I require which version of oracle is compatible with windows vista and the links from which i can download. i tried 9i and 10g which are not compatible . do i need any patchs ....in windows ?

  • T5140 will not boot to OS

    I am unable to boot my T5140 Sparc Enterprise server. I can only get to the ILOM web interface and SER MGT interface. Once to the -> prompt I can start /SYS and start /SP/console but and that point all I get is a blinking cursor even after waiting a

  • How can i add and delete node in tree in run time

    i want to know the method that let me select tree node to delete it and another to input upon user inputs

  • Contacts on my new phone

    I have put my sim card in my new iphone4s but itunes has backedup my very old contacts where can I get my new contacts

  • Interface View 10G vs 11G

    Hi All, In 10G when we click a interface in operator we can see all the sub steps on the right side of the operator where as in 11G (11.1.1.6.3) i am not able to see. Can you please let me know if something can be done? May be applying a patch or so?