I have a JTable with a refresh button. When I click the refresh button, the JTable is updated, so this works fine. Now I want to trigger automatically the refresh button with the button.doClick() method (just for testing), which I have placed in the constructor, so that the JTable would be updated each time a new instance of the JTable would be called.

The button2.doClick() method works fine in that way that all commands in the actionPerformed() method are executed. But what doesn't work is that the JTable is not refreshed when I use the button2.doClick() method. On the other hand, when I click on the refresh button (button2), then the JTable is refreshed. So what have I missed?

01-11-2011, 07:16 PM

hosscomp

Need to see the code.

01-11-2011, 10:47 PM

javaevgny

Here's the code of the whole class. It's just a part of a package. I hope this helps to figure out the problem.

if (y==1) day = "monday";
else if (y==2) day = "tuesday";
else if (y==3) day = "wednesday";
else if (y==4) day = "thursday";
else if (y==5) day = "friday";
else if (y==6) day = "saturday";
else if (y==7) day = "sunday";

//Create and set up the window.
JFrame frame = new JFrame("Bookinglist");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the content pane.
tableExample5 newContentPane = new tableExample5(dateSample);
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);

//Display the window.
frame.pack();
frame.setVisible(true);
}

}

01-11-2011, 11:16 PM

Fubarable

I've added code tags to your code to help make it readable. To see how to do this yourself, please read the link in my signature links below.

I wonder if your problems are because you're calling doClick in the constructor before any components have been rendered.

Edit: Also, we don't know what FileHandling2 does. I recommend that you try to simplify your problem to a minimal GUI that reproduces the problem, an SSCCE as this exercise will often show you the problem, and if not, gives us a small workable GUI that we can test and modify. Please see my other signature link about how to create one of these.

01-11-2011, 11:46 PM

hosscomp

I agree with Fubarable. We can't see what is happening as it is.
Have you tried making refresh() a seperate method that is called from both the listener and the constructor?

01-14-2011, 05:26 PM

arafat877

Hi !
I have developed a client/server application, witch the client is a swing based frame witch contains à jtable, if client A adds/updates.removes a row, the other users must see the changes without clicking a button to refresh the jtable, I read some articles on the net, in witch they uses SwingWorker, java.swing.Timer, but I can't use this solutions because I don't undertand it .

king regards

01-14-2011, 05:28 PM

Fubarable

Please do not hijack another's thread. If your question is important, ask it in its own thread. Locking this thread. Thank you.