Sunday, June 9, 2013

Java JTable using NetBeans GUI builder

This post explains how to create JTable with netbeans GUI builder.
Reading Oracle JTable tutorial will help a lot.
http://docs.oracle.com/javase/tutorial/uiswing/components/table.html


CAUTION!
I'm self-taught programmer, so the infomation in this blog may not right.
It would be great if someone tell me where Im wrong.


1. first start up the netbean and create a new project.  Then create new JPanel form file



2. Then you get the below result. Check the right side of netbeans, and you see palette 
and properties.  click those. 




3. From properties tab, you can check the properties of the selected componet.  From Palette tab, you can check various components you can use




4. I want my table to fully fill JPanel, 
so choose Border Layout for the JPanel we've created above



5. now add Scroll Pane to the JPanel. 
Scroll Pane is added automatically when putting JTable, 
but I just add it manually.
This will allow my table to have scroll bar when the displaying window is too
small to fully display the table.
You can check the Scroll Pane is added at the navigator tap at the 
low left corner of the netbeans 




6. Click the Scroll pane and drag&drop it on the JPanel. 




7. Now time to add JTable. Click the Table and drag&drop on the JPanel. 





8. Now we have a simple JTable. as below



9. you can change the number of rows and columns and data of the table by 
right clicking the table name on the left below side.  
You can see the jTable1 object is highlighted as blue in the above screen shot. 
Those process are fairly simple and straight forward, so I omit it. 



At the next post, I will explain how to manipulate the source code of the table  

No comments:

Post a Comment