aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How do you format the a particular cell of a JTable to accept different datatypes ?!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How do you format the a particular cell of a JTable to accept different datatypes ?!!" Watch "How do you format the a particular cell of a JTable to accept different datatypes ?!!" New topic
Author

How do you format the a particular cell of a JTable to accept different datatypes ?!!

Meghna ks
Ranch Hand

Joined: Mar 15, 2001
Posts: 122
Hi guys, Here's my question. Typically, I've observed that a particular column of a JTable can be rendered and made to accept a particular data type or a combobox to show up or a textbox to show up etc. How do I get a particular column of a JTable to accept different data types and components . i.e for eg. the second column of a Table can have an Integer, a string , a boolean(checkbox must show up), a Date/Time(a combobox should show up) .. How can this be done ?!!
Thanks
Meghna
suri
Greenhorn

Joined: Apr 28, 2001
Posts: 3
http://www.javaworld.com/javaworld/javatips/jw-javatip102.html
this link may be helpful to you.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Meghna, There are several examples of this in chapter 18 freely available here:
http://www.spindoczine.com/sbe
In particular I would take a look at the expense report example.
-Matt
------------------
Matthew Robinson
matt@mattrobinson.com
co-author of "Swing" (1999, Manning Publications). Freely available at http://www.spindoczine.com/sbe
Meghna ks
Ranch Hand

Joined: Mar 15, 2001
Posts: 122
Hi Matt
I did go through the expense report example and its very well explained. But, I've seen Tables having same type of data for a particular column , i.e 1st column - Date, 2nd column - Time,
3rd column - combobox and so on. What I was wondering was if it is possible to fit it multiple data types in a single column !!
For eg :
------------------------
First Column
------------------------
Date
Time
Checkbox(Boolean)
Combobox(List of Values)
IPAddress
-------------------------
Have you come across any examples of this type in JTables ?!! Please let me know if you come up with any ideas ?!!
Thanks
Meghna
Swamy Vatti
Ranch Hand

Joined: May 02, 2001
Posts: 57
Check this...
Sure u'll have a solution
http://eos.dk/archive/swing/frm05136.html

Swamy
Matt Robinson
Greenhorn

Joined: Apr 30, 2001
Posts: 28
One way is to override your table's getCellRenderer and getCellEditor methods check the row and column and return the renderer or editor you'd like to use for that particular cell
------------------
Matthew Robinson co-author of "Swing" (1999, Manning Publications). Freely available at http://www.spindoczine.com/sbe


Matthew Robinson<BR>matt@mattrobinson.com<BR>co-author of "<a href=http://www.amazon.com/exec/obidos/ASIN/189311578X/ref=ase_electricporkchop/107-7882751-0234939 target=newwindow rel="nofollow">Swing</a>" (1999, Manning Publications). Freely available at <A HREF="http://www.spindoczine.com/sbe" TARGET=_blank rel="nofollow">http://www.spindoczine.com/sbe</A>
 
 
subject: How do you format the a particular cell of a JTable to accept different datatypes ?!!