Consider this: you have a running Java application with a Swing front-end and a PostgreSQL database managing the data in the backend. You want to let your users view and modify the data in your database, but they don’t know a smidgen of SQL. Perhaps there is a way to (easily?) draw a GUI front-end using Swing components on the Java side.
This question came up for me while I was working on a recent project. In the end, I was able to create a working GUI front-end that would allow the user to insert, remove and modify entries in my database.
In the next series of posts, I’ll be outlining some details on how I went about creating the GUI front-end. So lets get started!
To begin with, we need to choose an appropriate JComponent to display our database entries. JTables are the best suited for this job. They are essentially static tables that are pre-loaded with data. As with most things Swing, we’ll need to modify and extend some of the classes used by JTable before we can turn it into something useful.
But before you go off tearing through the API, make sure you take a look at the JTable tutorial on the sun website. You don’t have to study it like the Bible, but read it over to get a good handle on how JTables work. In order to display our database entries, we’ll need to extend the AbstractTableModel class to create our own TableModel object. This will give us a greater degree of control over how our JTable behaves when we start to fill it with more information.
Next: Pt 2. Extending AbstractTableModel to create your own JTable >>

2 Trackbacks
[...] JTables + JDBC – Pt.1 Introduction RSS feed [...]
[...] linking up your JTable with a database through JDBC (see previous post here), you might find the need to add and remove rows to your table through the application [...]