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

Add, Edit and Delete JTable with Database  RSS feed

 
Jordan Kinsella
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I currently have all the code working to fill my database and to display it, although I would like to have it displaying in a JPanel but I cannot figure it out so a JFrame will do. The question I am here to ask though is anybody able to help me with a Add,Edit and Delete button for the JTable so I can add rows to the table and database, edit existing rows and delete rows also. Can Anybody help me with the code for this ? Thanks.

Here is the code for my current class.

 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Since you are using a database, I would suggest using a JDialog displaying the necessary fields representing the customer for insert and update.

Your main window can look like using BorderLayout as example:
JTable in BorderLayout.CENTER
Add, update, delete buttons in BorderLayout.SOUTH

When the button is clicked, JDialog (for insert/update) or confirm box (for delete) pops up, does its stuff and refreshes the data in the JTable's model.


The above is just one way to display the components.

 
Jordan Kinsella
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, thanks for the reply. I'm not the best at programming and I don't really understand a lot what you mean. I am able to post any code needed. I created the buttons on the JTable all I need to do is enter the code for the buttons to function. Thanks.
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The key to setting up the GUI is the layout. If you draw it out on paper will help.


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!