Swing Tutorial in Matisse - Custom Table Models

The continuing adventures of the Swing Tutorial in NetBeans and Matisse. In yesterday's blog, I talked about how it's a pain that when you define the data for your JTable's model in some defined arrays of strings and objects, the data doesn't show up in the design view.

In real-world applications, however, you're most likely going to define your custom TableModel to do things like access a database. For example, TableDemo.java sets up MyTableModel as an inner class. So how do you get this set up in the IDE?

Once again, we're using the model property editor for the JTable (select the JTable - not the JScrollPane - in the Inspector window and click the button for the model property in the Properties window). One simple way to do this is to switch to Form Connection mode, select User Code, and just enter new MyTableModel(). If you run the file, you'll see the model is properly used. But in the design view, we still see nothing.

A better way is to copy the MyTableModel class to its own separate class, called MyTableModel, of course. Then build the project (you need a binary version of MyTableModel for what we're about to do). Now select MyTableModel in the Projects window and press Ctrl-C, then paste it anywhere in the design view (or select any node in the Inspector and paste). An instance of MyTableModel gets added to the Other Components node.

Now we can go back to the model property editor for the JTable, select From Bean, and select myTableModel1. And voila, the data appears in the design view.

This and much more is coming up in an excellent tutorial being prepared by Talley Mulligan on hooking up a Matisse GUI form to a DB back-end, so stay tuned for the full story.

Comments:

fuck

Posted by guest on May 12, 2006 at 08:32 AM CEST #

Thanks for this tip (I guess the last commenter was impressed as well). The Netbeans tutorials I've seen all seem to stop after the GUI has been layed out, and don't discuss how to hook things up.

Posted by Dave on May 13, 2006 at 07:53 AM CEST #

Thanks for this tip (I guess the last commenter was impressed as well). The Netbeans tutorials I've seen all seem to stop after the GUI has been layed out, and don't discuss how to hook things up.

Posted by Dave on May 13, 2006 at 07:54 AM CEST #

he he he, yes, that's the reaction I like to see. Dave, like I said, one of our docs guys, Talley, is putting the finishing touches on doing a full tutorial to hooking up the GUI to a DB back-end. It's snazzy. Stay tuned.

Posted by johnc on May 16, 2006 at 10:11 AM CEST #

Post a Comment:
Comments are closed for this entry.
About

johnc

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today