Sunday, June 9, 2013

Java JTable using NetBeans GUI builder 2


Topic. 
How to create a table with check box. 


In the last post, I covered how to create a basic JTable using netbeans GUI builder.
The problem of using only GUI builder is that it is hard to change the contents as I want.
So netbeans allows users to change the source code, but I find it hard to use.

I think making table using netbeans GUI builder is somewhat inefficient,
but I cant give up using the builder since builder other components such as
buttons and combo box too convenient.

So in this post, I will cover how to create a modified table using the netbeans GUI builder.





Last post, I've created a simple JTable as below




now, I want to change the header as

Name | Level | Vegetarian 

with Vegetarian column as check box.

This can be done very easily as follows.



First, right click the jTable1 in the navigator tab, and choose Table contents. 


Then the following window pops up. 


from there, you can easily change the header name and data of the table. 

You can get the check box in a column by changing the Type of the column 
from object to boolean



This is very straight forward, so I omit the explanation


so now I have the following table. 



now, lets check the source code of this table.
You can check the source code by clicking here





As you can see, most of the code has gray background.  The gray background means
you cannot change the code directly. This makes coding very uneasy to me.
To code into that gray background, you have to do this.

First, go back to design tab (click the Design button right next to the Source button)
Then, right click the jTable1 object in the navigator tab as before, and go to properties.


From there you go to code tab, 



And there, you can code into the gray area.  Play with it and you will see 
which part directs what part in the gray area. 







At the next post, I will do the exact same task by manual coding.








No comments:

Post a Comment