Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

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

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.javaworld.com/javaworld/javatips/jw-javatip102.html
this link may be helpful to you.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this...
Sure u'll have a solution
http://eos.dk/archive/swing/frm05136.html
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic