tags:

views:

24

answers:

4

I have a column for images. I would like to attach some additional text information that will only be read but not for display.

How can I achieve this ? I am looking for some "ghost" column.

Looking for some way to store persistent data that stores temporarily on client java application, and later uploads it to the server.

+1  A: 

It would be helpful to see what your TableModel looks like, as we could give you ideas that would offer minimal changes to your current design. However, one solution would be to design a custom data object that would represent a row in your table, and have your TableModel use it to supply the correct data for each column, including the image that you currently display.

edit:

basically I have a single column table and DefaultTableModel set up with 2 columns. I would like only the first column of the Model to display.

I would suggest that you create your own TableModel by extending AbstractTableModel. For that you just need to implement three methods:

public int getRowCount();
public int getColumnCount();
public Object getValueAt(int row, int column);

You then could provide a backing collection like a List to hold your row data. Your getRowCount() could return the size of the list, your getColumnCount() could return 1 for your picture column. getValueAt() would then return the picture from the custom data object that I mentioned above.

akf
basically I have a single column table and DefaultTableModel set up with 2 columns. I would like only the first column of the Model to display.
Kim Jong Woo
A: 

You need to extend AbstractTableModel or DefaultTableModel class and override getValueAt(row,column) and setValueAt methods.

harshit
A: 

Are you using a custom TableModel? You can override getColumnCount() like this:

@Override
public int getColumnCount() {
    return super.getColumnCount() - 1;
}

This way your model will have the last column hidden, but you'll still be able to read it with getValueAt()

tulskiy
+1  A: 
  1. Create the TableModel normally with two columns of data
  2. Create the JTable using the TableModel
  3. Get the TableColumnModel from the JTable
  4. Remove the TableColumn (from the TableColumnModel) that you don't want displayed in the table. This will NOT delete the data in the model, it just won't paint the column in the view of the table.

Now when you want to reference the data in the hidden column you need to get the data from the TableModel, not the JTable:

Object cellData = table.getModel().getValueAt(...);
camickr