• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable issues

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have 2 issues which i am currently facing regarding displaying and using the Jtable component in urlybird 1.3.1

1.
I am having an issue at present whereby i need to ba able to hide from the user the data in a particular column in the Jtable as the data is not for user viewing purposes.

I have a seperate class for the TableModel which represent the data which is stored in the JTable so

TableModelClass temp = new TableModelClass;
JTableClass main = new JTable(temp);

However i only want to display 9 of the 10 columns in the JTable. Does anyone know the code which will allow me to do this. By the way i need to just hide this column data from the user but it needs to be in the JTable as
the column data contains primary keys which are used for data retrieval in other parts of the application.

Is there any code to size the reduce a particular column width size to zero?

2. I would like to know how anyone else worked around the issue of trying to display a HashMap in a JTable. I am storing bookings from the database file in a hashmap whereby the key value is the filepointer to the record on file and the booking instance is stored with this key. I suspect i may need to store this data in an ArrayList rather than in a HashMap in my TabelModel class in order for the JTable to display the Bookings correctly here but i am not sure?? I am wondering how others worked around this issue?

Any help would be appreciated on either of these issues.

david
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David,

(First Question)

However i only want to display 9 of the 10 columns in the JTable. Does anyone know the code which will allow me to do this. By the way i need to just hide this column data from the user but it needs to be in the JTable as
the column data contains primary keys which are used for data retrieval in other parts of the application.



In your implementation of the TableModel you can extend javax.swing.table.AbstractTableModel and then provide your own definitions of:


This should allow you to hide the column but keep the data in the model.

(Second Question)

I would like to know how anyone else worked around the issue of trying to display a HashMap in a JTable. I am storing bookings from the database file in a hashmap whereby the key value is the filepointer to the record on file and the booking instance is stored with this key. I suspect i may need to store this data in an ArrayList rather than in a HashMap in my TabelModel class in order for the JTable to display the Bookings correctly here but i am not sure?? I am wondering how others worked around this issue?



There is constructor of DefaultTableModel as follows:



Personally I kept the record data as an array which made my implementation of the getValueAt() method listed above very easy.



Hope that is of some help.

Regards,

Tom
[ January 22, 2008: Message edited by: Thomas Hubschman ]
 
David Winters Junior
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply tom.

For the first issue i have found the solution to hide a particu;ar column


I have decided to use the TableColumn api which has a setMaxwidth() method which will allow me to set the column width to zero.

http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/table/TableColumn.htm

Regarding the second issue at hand im not sure if it will work in my case. I figure i best use an ArrayList type in a TableModel class to store data to be displayed in the JTable.

Data in my Hashmap which i use a cache to store records from the database looks like this:

key object

74 Booking
140 Booking


The key value above points to the location on file where the record is stored and the booking contains the releavnt database fields.

So i need to have the key as part of the data which i display in the Jtable so that when the user clicks the button on the UI to remove the record after selecting it the underlying record key is assocaited with the row object so that i can then use this key value to remove this record from the hashmap and db file.

I wonder if changing my design not to use a hashmap and instead use an arraylist to store records in my cache whereby the Booking object will contain a field to store the key or pointer to the record on file??

David
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic