Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable not getting updated  RSS feed

 
Aravind Prasad
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ranchers

I am preparing a small solution. Below is how the functionality works.

1. Login Screen
2. Successful Login will take to a MDI Form
3. Click the menu, a JInternalFrame will open in the JDestopPane.
4. JInternalFrame has a JTable.
5. JInternalFrame has a JButton available for adding new data.
6. When JButton is clicked, a new JInternalFrame is popped up with some JTextField and JButton to save the data.
7. After saving the data (after insert query), a JDialog is opened to upload Logo (update query for BLOB), There are two buttons in the JDialog, one is for uploading the image, another one is uploading it later.
8. The logo is displayed in the JDialog and if the JButton, for upload is pressed, update the database and reload the JTable in the JInternalFrame is called.

My challenge is in point 8. The function is called properly, but the table is not getting refreshed.

Below provided my code, can you please help to understand where i went wrong.

JButton in JDialog for uploading the Logo


Code in the JInternalFrame to populate JTable

>
 
Campbell Ritchie
Sheriff
Posts: 55333
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aravind Prasad wrote: . . . Below is how the functionality works.

1. Login Screen
2. Successful Login will take to a MDI Form
3. Click the menu, a JInternalFrame will open in the JDestopPane.
4. JInternalFrame has a JTable.
5. JInternalFrame has a JButton available for adding new data.
6. When JButton is clicked, a new JInternalFrame is popped up with some JTextField and JButton to save the data.
7. After saving the data (after insert query), a JDialog is opened to upload Logo (update query for BLOB), There are two buttons in the JDialog, one is for uploading the image, another one is uploading it later.
8. The logo is displayed in the JDialog and if the JButton, for upload is pressed, update the database and reload the JTable in the JInternalFrame is called. . . .
Ignore 95% of that. Focus on how to pass things to the database. That is all the functionality you want. And the way to get that is to remove all the GUI code and run your commands from the command line. No buttons no internal frames only command line.
Go through the Java Tutorials about databases. Run your code until you can reliably pass an UPDATE command and have the database correctly updated. Then you can add a GUI.
 
Aravind Prasad
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But Boss

The data is saving properly in the database. The issue is with JTable. I have an updateTable Function, even if i am calling the function, it is not refreshing the data. That is my issue. Infact i have tried also repaint(), but still failing.

I have described the functioanlity such that, you might be able to assume the path/parent frame where the JDialog is opening.

Thanks/Regards

Aravind
 
Campbell Ritchie
Sheriff
Posts: 55333
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
|I think you will find the Java Tutorials link I gave pearler has a section in about JTables.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are doing some incorrect things in the code:
a) Class names should begin with uppercase - 'companyConfigs' is poor naming convention
b) You create an ArrayList with 'new ArrayList()' and immediately in the next line assign the variable to something else. Why? Just declare the variable and assign it. Why create the new list unnecessarily?
c) The if clause is empty - how do you know code is not entering there?
d) Most importantly, you create an 'companyConfigs' instance in the button click with which you invoke the 'updateTable' method - and then, inside the 'updateTable' method, you again create another instance of 'companyConfigs' - why? no wonder you don't see the data. I am sure the code is getting into the 'if' clause.

My suggestion would be to take a step back, understand OOPS concepts, classes etc. and revisit this.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!