Doing new JTable doesn't "update" the table on the screen

Hello
I am writing a program in java/swing which has several "layers" of panels. In the constructor method of the frame (using JInternalFrame) I create a new instance of JTable, place it inside JScrollPane which is then inside JSplitPane and then place that as the frame content pane.
In this program I run an sql command and the table is the result from that. Every time I execute a query it should update the table with the new results.
What is bothering me now is that when I execute a query I call new JTable() on the variable that held the JTable() object created on startup. When I create a new instance of JTable() and place it in this variable nothing seems to happen. What I need is some kind of "refresh" button. I tried to construct the whole window again but then the program started behaving odd so I gave up that method.
So, does anyone know how to do this?
The code behind this class can be found at http://www.heilabu.net/kari/Session.java (little commented, sorry :/)
You can see the table being constructed in the constructTable() method.
If I am a bit unclear I apologize, don't know all these technical words in english ;)
Thanks in advance!

You really need to use a table model. The table you created is great and once that is in you shouldn't mess with it. Instead, when you create the table be sure to create it sort of like this:
DefaultTableMode dtm = new DefaultTableModel(<various constrcutors use the one suited for you>);
JTable table = new JTable(dtm);
To set different data on the table set it in the table model and then refresh the table, also through the table model. This works perfectly every time.
dtm.setDataVector(---) <- 2 methods, one for vectors and one for arrays...
dtm.fireTableChanged();
the folowing code shows exactly how to use it
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
public class RandomTable extends JFrame
GridBagLayout gbl = new GridBagLayout();
JPanel buttonPanel = new JPanel(gbl);
JTable table = null;
DefaultTableModel dtm = null;
JScrollPane tableSP = new JScrollPane();
JButton randomButton = new JButton("Randomize");
Object[] headers = { "a", "b", "c", "d", "e" };
public RandomTable()
this.getContentPane().setLayout(gbl);
randomButton.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent evt)
dtm.setDataVector(randomStrings(), headers);
this.dtm = new DefaultTableModel();
this.table = new JTable(dtm);
this.dtm.setDataVector(randomStrings(), headers);
this.tableSP.getViewport().add(table);
this.buttonPanel.add(randomButton, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
this.getContentPane().add(buttonPanel, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 6, 6, 6), 0, 0));
this.getContentPane().add(tableSP, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(6, 6, 3, 6), 0, 0));
this.setSize(300, 300);
public Object[][] randomStrings()
Random rand = new Random();
int rowCount = Math.abs(rand.nextInt())%50;
int colCount = headers.length;
Object[][] array = new Object[rowCount][colCount];
for(int row = 0; row < rowCount; row++)
for(int col = 0; col < colCount; col++)
array[row][col] = Long.toString(Math.abs(rand.nextLong())%100);
return array;
public static void main(String[] args)
RandomTable rt = new RandomTable();
rt.setVisible(true);
}

Similar Messages

  • Updating two tables at the same time

    Please,
    Does someone have an idea on how to update two tables at the same times?
    Thanks a lot in advance

    I was thinking about a single session and single update command.
    That's why I thougth someone else could have a clue.
    Thank you

  • Two forms that update differrent tables on the same page?

    I tried to add two forms that update different tables on to one page.
    Problem is when I do that the forms gives me an error saying the field does not exist. It's like it is trying to update one table with the other tables fields.
    As an example Say I have one forms that is for people table and another one that is the Jobs table.
    When I go to update the people table, it sends the data for the jobs fields too I get an error like the field job description does not exist.
    I have two different forms for these and everything.
    I would hope it is possible to have two forms that update different tables on the same page.

    I was trying the exact same thing, but i managed to work round it by setting the steps to hide one region, so the user would enter the form see one region submit the region then direct back to the same page with the different region visible and the original hidden.
    I don't know if this would be acceptable for you...

  • Reading and Updating the table at the same time

    Hi all
    I need to read from a table to check whether a record exist in there or not, then  if not add the record to the table (in the same dataflow). Is there any way to use a table as a source and as a target at the same time?
    While I'm doing this procedure, I don't want to add a record that I had inserted before twice  (I need to get the latest veriosn of the table when I'm working with that). For example, in the same process, when I check the table and the record was not there, I insert the record, I read the table again , if this time again I want to read the same record that I had inserted just before, does DS distingish that, or all records will be comitted based on the commit size which is by default 1000?
    I can not change the commit size to 1 to tell DS to commit record by record, as I have turned on the transactional load and the commit size is disabled for me.
    Do you have any experience about my problem?
    Any help is greatly appreciated.

    You need two dataflows. A first that reads your source and inserts/updates the lookup table. And then you read your source again and use the now current lookup table.
    Even if you would set the commit rate to 1 it would not help as there are so many buffers between the transforms. What you would require is that only one row is in the dataflow at any given time - and that would take ages.

  • I bought games and music on my ipod touch and then bought a new mac, but i updated my ipod on the new mac and lost all of my games and music and they arent on my computer or my ipod touch:( The apps i bought are not on my old computer either!! please help

    bought games and music on my ipod touch and then bought a new mac, but i updated my ipod on the new mac and lost all of my games and music and they arent on my computer or my ipod touch:( The apps i bought are not on my old computer either!! please help!!! I don't want to buy them all again!!

    - You can redownload yur apps at no additional cost.  See:
    How to redownload purchased apps from the App Store
    - You only get one download of music and it is up to you to make a backup.  However, sometimes if you explain what happens the iTunes store may allow a redownload of music.  You can contact them by starting here and selecting the appropriate topic:
    Apple - Support - iTunes

  • Updates to the table from the database level.

    Hi Dear All,
    If we do some updates to the table at the Database Level, like i deleted some records from the table at the Oracle level. But I'm still able to see the same deleted records from the Data Dictionary(SE11) at the application level.
    Can you pl explain the mechanism, that how it is possible and why.
    best regards
    Mahesh

    transparent tables store data directly....if you delete some data from transparent tables, the same is reflected in the database (oracle) but the reverse is not true...if you modify the database table contents directly...the dictionary table remains intact...
    transparent tables have a one-to-one relationship with the database tables....
    hope that clarifies a bit....
    (somebody correct me if i am horribly wrong)

  • Does new lion migration assist from windows xp delete the files on Pc?

    Does new lion migration assist from windows xp delete the files on the pc or just copy them? Especially for outlook 2003 as I don't want my emails deleted off the pc

    Zingerbottom wrote:
    Does new lion migration assist from windows xp delete the files on the pc or just copy them? Especially for outlook 2003 as I don't want my emails deleted off the pc
    No everything that was on the PC remains there.

  • Cannot display all the tables of the schema!!!

    Hi:
    I use the oracle sql developer on the windows xp, I found that the tables tab cannot display all the tables of the schema owner, I use the sql "select count(*) from user_tables" I found the result is more than the tab can be display, and I also press the "show more" already.... does anyone can help me ???

    Similarly, I have 852 tables owned by the connected user (selected count from user_tables and checked the user tables report which has this many records returned), but when I double-click on the "Show More" and select Show All, I only get approximately 375 tables listed.
    It doesn't help that the sorting is different - ie ASF_ comes before ASFB in the connection pane but the other way around in the report.
    However, it looks as though the problem is that tables that are not analysed (based on the report data in DATE_LAST_ANALYZED) are not being displayed under the Table node.

  • Add data to the table in the database with the use of add button

    The name of my database is Socrates.
    The name of the table in the database is Employees
    I want to be able to add data to the database. i am presently working on the add button such that when i enter date into the textfield and press the add button it should automatically register in the table.
    The error upon compilation is with this line of code
    If (ae.getSource() == jbtnA)// it says that ";" is expected
    Below is the entire code
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Mainpage extends JFrame implements ActionListener
         JTextField jFirstName = new JTextField(15);
         JTextField jSurname = new JTextField(12);
         JTextField jCity = new JTextField(10);
         JTextField jCountry = new JTextField(12);
         JTextField jSSN = new JTextField(8);
         JLabel jFirstLab = new JLabel("First Name");
         JLabel jSurnameLab = new JLabel("Surname");
         JLabel jCityLab = new JLabel("City");
         JLabel jCountryLab = new JLabel("Country");
         JLabel jSSNLab = new JLabel("Social Security Number (SSN)");
         JButton jbtnA = new JButton ("Add");
         JButton jbtnPrv = new JButton ("Previous");
         JButton jbtnNt = new JButton ("Next");
         JButton jbtnDl= new JButton ("Delete");
         JButton jbtnSrch = new JButton ("Search");
         public Mainpage (String title)
              super (title);
              Container cont = getContentPane();
              JPanel pane1 = new JPanel();
              JPanel pane2 = new JPanel();
              JPanel pane3 = new JPanel();
              pane1.setLayout (new GridLayout (0,1));
              pane2.setLayout (new GridLayout(0,1));
              pane3.setLayout (new FlowLayout());
              pane1.add(jFirstLab);
              pane1.add(jSurnameLab);     
              pane1.add(jCityLab);
              pane1.add(jCountryLab);
              pane1.add(jSSNLab);
              pane2.add(jFirstName);
              pane2.add(jSurname);
              pane2.add(jCity);
              pane2.add(jCountry);
              pane2.add(jSSN);
              pane3.add(jbtnA);
              pane3.add(jbtnPrv);
              pane3.add(jbtnNt);
              pane3.add(jbtnDl);
              pane3.add(jbtnSrch);
              cont.add(pane1, BorderLayout.CENTER);
              cont.add(pane2, BorderLayout.LINE_END);
              cont.add(pane3, BorderLayout.SOUTH);
              jFirstName.addActionListener(this);
              jSurname.addActionListener(this);
              jCity.addActionListener(this);
              jCountry.addActionListener(this);
              jSSN.addActionListener(this);
              jbtnA.addActionListener(this);
              jbtnPrv.addActionListener(this);
              jbtnNt.addActionListener(this);
              jbtnDl.addActionListener(this);
              jbtnSrch.addActionListener(this);
              validate();
              setVisible(true);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              pack();
              setResizable(false);
         public void actionPerformed(ActionEvent ae)
                   If (ae.getSource() == jbtnA)
                                    fst = jFirstName.getText();
                        srn = jSurname.getText();
                        cty = jCity.getText();
                        cnty = jCountry.getText();
                        int sn =
    Interger.parseInt(jSSN.getText());
                                    String ad = "Insert into Employees
    (Firstname,Surname,City,Country,SSN)" +
    "values('"fst"','"srn"','"cty"','"cnty"','"sn"')";
                        Statement stmt = con.createStatment();
                        int rowcount = stmt.executeUpdate(ad);
                        JOptionPane.showMessageDialog("Your
    details have been registered");
                        Statement stmt = con.createStatment();
                        int rowcount = stmt.executeUpdate(ad);
    public static void main (String args[])
              Mainpage ObjFr = new Mainpage("Please fill this
    registration form");
              try
                   Class.forname("sun.jdbc.odbc.JdbcOdbcDriver");
                   String plato = "jdbc:odbc:socrates";
                   Connection con =
    DriverManager.getConnection(plato);
              catch(SQLException ce)
                   System.out.println(ce);
    }

    i have restructured the code, but the following line of code is giving error:
    String plato = jdbc:odbc:socrates;
    the entire code is below:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.sql.*;
    public class Mainpage extends JFrame implements ActionListener
         JTextField jFirstName = new JTextField(15);
         JTextField jSurname = new JTextField(12);
         JTextField jCity = new JTextField(10);
         JTextField jCountry = new JTextField(12);
         JTextField jSSN = new JTextField(8);
         JLabel jFirstLab = new JLabel("First Name");
         JLabel jSurnameLab = new JLabel("Surname");
         JLabel jCityLab = new JLabel("City");
         JLabel jCountryLab = new JLabel("Country");
         JLabel jSSNLab = new JLabel("Social Security Number (SSN)");
         JButton jbtnA = new JButton ("Add");
         JButton jbtnPrv = new JButton ("Previous");
         JButton jbtnNt = new JButton ("Next");
         JButton jbtnDl= new JButton ("Delete");
         JButton jbtnSrch = new JButton ("Search");
         Statement stmt;
            String ad;
            public Mainpage (String title)
              super (title);
              Container cont = getContentPane();
              JPanel pane1 = new JPanel();
              JPanel pane2 = new JPanel();
              JPanel pane3 = new JPanel();
              pane1.setLayout (new GridLayout (0,1));
              pane2.setLayout (new GridLayout(0,1));
              pane3.setLayout (new FlowLayout());
              pane1.add(jFirstLab);
              pane1.add(jSurnameLab);     
              pane1.add(jCityLab);
              pane1.add(jCountryLab);
              pane1.add(jSSNLab);
              pane2.add(jFirstName);
              pane2.add(jSurname);
              pane2.add(jCity);
              pane2.add(jCountry);
              pane2.add(jSSN);
              pane3.add(jbtnA);
              pane3.add(jbtnPrv);
              pane3.add(jbtnNt);
              pane3.add(jbtnDl);
              pane3.add(jbtnSrch);
              cont.add(pane1, BorderLayout.CENTER);
              cont.add(pane2, BorderLayout.LINE_END);
              cont.add(pane3, BorderLayout.SOUTH);
              jFirstName.addActionListener(this);
              jSurname.addActionListener(this);
              jCity.addActionListener(this);
              jCountry.addActionListener(this);
              jSSN.addActionListener(this);
              jbtnA.addActionListener(this);
              jbtnPrv.addActionListener(this);
              jbtnNt.addActionListener(this);
              jbtnDl.addActionListener(this);
              jbtnSrch.addActionListener(this);
              validate();
              setVisible(true);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              pack();
              setResizable(false);
              try
                   Class.forname(sun.jdbc.odbc.JdbcOdbcDriver);
                   String plato = jdbc:odbc:socrates;
                   Connection con = DriverManager.getConnection(plato);
                   stmt = con.createStatment();
              catch(SQLException ce)
                   System.out.println(ce);
              catch(ClassNotFoundException ce)
                   System.out.println(ce);
         public void actionPerformed(ActionEvent ae)
                   try
                        if(ae.getSource().equals(jbtnA))
                                         fst = jFirstName.getText();
                             srn = jSurname.getText();
                             cty = jCity.getText();
                             cnty = jCountry.getText();
                             int sn = Interger.parseInt(jSSN.getText());
                                         ad = "Insert into Employees
    values('"+fst+"',"+srn+"','"+cty+"','"+cnty+"','"+sn+"')";
                             stmt.executeUpdate(ad);
                             JOptionPane.showMessageDialog(this, "Your details have been
    registered");
                   catch(SQLException ce)
                        System.out.println(ce);
    public static void main(String args[])
              Mainpage ObjFr = new Mainpage("Please fill this registration form");
    }

  • [CS3 JS]Get all the tables in the document

    Hello All,
    I want to return all of the tables in the document, including those in table cells. I am using this:
    var aTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
    but it doesn't get tables inside of tables. Is there an easy way to do this without checking each table cell? Thanks in advance.
    Rick Quatro
    585-659-8267

    Hi Robin and Dave,
    Thanks for your replies. This seems to work fine regardless of the nexting level.
    Rick
    var oDocTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
    if (oDocTables.length)
      oDocTables = GetAllTables(oDocTables);
    alert(oDocTables.length);
    function GetAllTables(oTables)
      for(var i=0; i < oTables.length; i++)
        var oCells = oTables[i].cells;
        for (var j=0; j < oCells.length; j++)
          var oCellTables = oCells[j].tables.everyItem().getElements();
          if (oCellTables.length)
            oTables = oTables.concat(oCellTables);
      return oTables;

  • How to get the column names of the table into the Dashboard prompt

    how to get the column names of the table into the Dashboard prompt
    Thanks & Regards
    Kishore P

    Hey john,
    My requirement is as follows
    I have created a Rank for Total sales by Region wise i.e RANK(SUM(Dollars By Region)) in a pivot table.
    My pivot table looks like this
    COLUMN SELECTOR: TOTAL US , REGION , DISTRICT , MARKET
    ---------------------------------------------------- JAN 2009          FEB 2009        MAR 2009
    RANK              REGION                  DOLLARS           DOLLARS        DOLLARS DOLLARS
    1 CENTRAL 10 20 30 40
    2 SOUTHERN 10 30 30 70
    3 EASTERN 20 20 20 60
    4 WESTERN 10 20 30 40
    When i select the District in column selector
    Report has to display rank based on Total Sales by District. i.e
    ------------------------------------------------- JAN 2009         FEB 2009       MAR 2009
    RANK             DISTRICT              DOLLARS           DOLLARS        DOLLARS DOLLARS
    for this i need to change the fx of rank i.e RANK(SUM(Dollars By Region)) to RANK(SUM(Dollars By District)) and fx of Region i.e Markets.Region to Markets.District dynamically.
    so , i need to capture column name of the value selected from the column selector and dynamically i need to update the fx 0f RANK & fx of region.
    do you have any solution for this?
    http://rapidshare.com/files/402337112/Presentation1.jpg.html
    Thanks & Regards
    Edited by: Kishore P on Jun 24, 2010 7:24 PM
    Edited by: Kishore P on Jun 24, 2010 7:28 PM

  • How to view the table at the application level

    Dear All,
    How to view the table in the Data Dictionary at the application level, If a table is created at the database level by using CREATE statement.
    code/
    create table zmard as select * from sapone.mard where 1 = 2
    /code
    I would like to view the table above, which is created at the Oracle database level in the Data Dictionary.
    can anyone guess the solution.
    Best wishes
    Mahesh

    Hi
    U should create a program using SQL native in order to select and show the data.
    By SE11 or directly in the program u can define a structure like your table:
    DATA: BEGIN OF W_ZMARD,
                  FIELD,
              END     OF W_ZMARD.
    EXEC.
       OPEN CURSO FOR SELECT * FROM ZMARD
    ENDEXEC.
    DO.
      EXEC.
         FETCH NEXT CURSOR INTO :W_ZMARD
      ENDEXEC.
      IF SY-SUBRC <> 0.
         EXIT.
      ENDIF.
      WRITE: / W_ZMARD-FIELD,
    ENDDO.
    EXEC.
      CLOSE CURSOR
    ENDEXEC.
    I don't know if it's possible to create a view in SE11, because it's needs a table just defined in SE11, u can create a new view ZMARD based on MARD but I don't believe it'll use your table.
    Max

  • Can the tables in the datamodel be ditributed among 2 different databases

    Hi,
    Please let me know whether the tables in the datamodel be ditributed among 2 different databases (for example between DB2 & Oracle).
    Thanks in advance!

    duffymo,
    Can you help me I am new to this one. Where do I do the JTA connection. Infact, is it a JTA configuration or is any coding required to handle that two-phase commit.
    would like to know more.
    Thanks

  • The performance of the tables in the PSAPSTABD is poor

    Hi:
    After I reorganized the tablepsace "PSAPSTABD" with datafile , I
    found that the performance for visiting the tables in the PSAPSTABD is
    very poor , and the tcode of maintaining the custom master data and
    material master data is very slow. The tools for the reorganization is
    SAPDBA 6.40 and the type of the reorganization is offline.Why? How can I solve it?
    THANKS.
    sap envirement: aix 5.3 + oracle 9.2.0.7 + sap r/3 46c sr2
    sap kernel : 46d_ext
    dbatools: I used dbatools 640 to overwrite the dbatools 620 and "sapdba" to reorg the tablepsace.

    Hy,
    is not easy understand the problem by your analysys...
    try to analyze a single trx that you consider very slow , and through st04(oracle session) let me know in which table the trx remains in hang or in waiting...then you should see the cost estimated for the query that is doing the trx. i mean that could be an index not correctly configured....
    Could be also a problem of table statistic..did you regenerate the statistic after the reorg of tablespace?
    let me know also database and tablespace dimension ...
    Bye bye
    Nick

  • In the table AIINSTALLATIONS the customer numer is missed

    Hi!
    I've got a small question: in the table AIINSTALLATIONS the field installation number is tilled out but the customer numer field is empty.
    Can you suggest me where I'm able to fix it?
    Thanks in advance

    SMSY_SETUP
    Write Data Back into SLD                          *
    Default CPU Load AC                                     85
    Multiple SLD Servers                          <empty field>                                                                           
    Hide Progress Display                     <empty field>                              
    SLD Host                                             <server name>
    Namespace in SLD                               sld/active
    SLD Server Port                                          50200
    SLD User                                               j2ee_admin
    AC CPU Load Warning Value                     65
    Generate Business Partners from OSS     C
    Generate Systems from OSS                     A
    JOB LOG
    Job started
    Step 001 started (program AI_SC_REFRESH_READ_ONLY_DATA, variant , user ID USERSAP)
    No destination for SAP customer number 733135
    No destination for SAP customer number 755727
    Identification Category SP0001 is Not Assigned to Any Identification Type
    Identification Category SP0001 is Not Assigned to Any Identification Type
    Business Partner 35 was created for customer 737370 with messages
    No destination for SAP customer number 1025117
    No installations flagged for system generation for customer 733135
    No installations flagged for system generation for customer 755727
    No installations flagged for system generation for customer 1025117
    System headers will be generated in SMSY from SAP Support Portal
    No new systems found in SAP Support Portal to generate in SMSY
    The following error messages have been returned by SAP Support Portal:
    User S0003352577 - "Maintain System Data" authorization not found for installation number 0020292124
    User S0003352577 - "Maintain System Data" authorization not found for installation number 0020298240
    User S0003352577 - "Maintain System Data" authorization not found for installation number 0020298240
    User S0003352577 - "Maintain System Data" authorization not found for installation number 0020298240
    User S0003352577 - "Maintain System Data" authorization not found for installation number 0020298241
    User S0003352577 - "Maintain System Data" authorization not found for installation number 0020298241
    User S0003352577 - "Maintain System Data" authorization not found for installation number 0020298242
    Installation number 000INITIAL not found
    The following error messages have been returned by SAP Support Portal:
    No system ZZ1 found for installation number 0020277953
    No system CN3 found for installation number 0020277955
    License data collected (customer number: 0000737370)
    Job finished

Maybe you are looking for

  • I have Design and Web Prem (Mac) I just got a new PC can I auth this too?

    I have Design and Web Prem (Mac) I just got a new PC can I auth this too?

  • How to get last page number in word report? LV

    I'm trying to find out where am I when I use LV to generate word report. I would like automatic generate page index in front of report. Thanks in advance

  • Function runs slower when rows affected are lesser

    Dear All, I have a stored function which accepts about 9 parameters and returns a number (1 or 0) the function can be executed as a check for security or access control along with any select query from the database Say i have 4 lakh entries in the da

  • Query with namespaces

    Hello, the issue is that when I make the query the objects returned are 0. The registries are like this: <Invoice xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:cac="urn:oasis:names:specification:ubl:schema

  • How to Web enabled my forms?

    Hi, Now i am working in two tier architech. I want to go for 3 tier. My database server --- Oracle 9i (Separate Sever,Linux) Forms and Reports execution files are kept into Separate server(Application,linux) Client side i am installing Runtime enviro