JScrollPane/JTable repaint problem

I've been developing a system that displays images on a JTable that is placed within a JScrollPane. The first time images are retrieved the table works fine but if I search for images again and expect them to be displayed on the screen, the system still displays the previous images. However if you click on the screen where the old images are being displayed it says that the image I'm clicking is one of the correct ones that have been retrieved but not been displayed. It seems to me like a repaint issue but I've tried calling repaint() and revalidate() etc but still no luck. Any ideas? Here the code where the table an scrollPane are created and populated// Create columns names

String columnNames[] ={"Retrieved images"};

// Create some data

Object data[][] =new Object[tableImagePathnames.size()][1];

System.out.println("Table contains " + data[0][0]);

for(int i = 0; i <tableImagePathnames.size(); i++)

{

//data[0][0] = (ImageIcon) new ImageIcon("C:\\Documents and Settings\\David\\My Documents\\David\\Individual Project\\Sample images\\Image segments\\Segments2\\angelinsnow1.jpg");

String imagePathname ="C:\\Documents and Settings\\David\\My Documents\\David\\Individual Project\\Sample images\\" + (String)(tableImagePathnames.elementAt(i));

//ImageIcon originalIcon = (ImageIcon) new ImageIcon("C:\\Documents and Settings\\David\\My Documents\\David\\Individual Project\\Sample images\\" + (String)(tableImagePathnames.elementAt(i)));

ImageIcon originalIcon = (ImageIcon)new ImageIcon(imagePathname);

Image scaledImage = ((ImageIcon)originalIcon).getImage().getScaledInstance(150, 150, Image.SCALE_SMOOTH);

ImageIcon newScaledImageIcon =new ImageIcon(scaledImage);

newScaledImageIcon.setDescription(imagePathname);

System.out.println("image pathname is " + newScaledImageIcon.getDescription());

System.out.println("Description is ");

data[i][0] = newScaledImageIcon;

System.out.println("Data at " + i +" ,0 is " + data[i][0]);

}

// Create a new table instance

DefaultTableModel model =new DefaultTableModel(data, columnNames);

table =new JTable( model )

{

publicboolean isCellEditable(int row,int column)

{

returnfalse;

}

public Class getColumnClass(int column)

{

System.out.println("Column class is " + getValueAt(0, column).getClass());

return getValueAt(0, column).getClass();

}

};// Add the table to a scrolling pane

table.addMouseListener(new TableCellListener());

table.setRowHeight(150);

table.setSize(200, 200);

table.setPreferredScrollableViewportSize(new Dimension(200, 200));

TableColumn tableColumn = table.getColumnModel().getColumn(0);

tableColumn.setPreferredWidth(160);

tableColumn.setMaxWidth(160);

tableColumn.setWidth(160);

table.revalidate();

table.repaint();

table.updateUI();

//scroller.getViewport().add(table);

scroller =new JScrollPane(table);

scroller.setSize(200, 200);

//scroller.getViewport().add(tempPanel); //really want to add the images to a grid layout panel then add the panel to the scroller

scroller.revalidate();

scroller.repaint();

scroller.updateUI();

constraints.gridx = 2;

constraints.gridy = 0;

constraints.gridwidth = 2;

constraints.weighty = 0;

constraints.gridheight = 6;

mainPanel.add(scroller, constraints);

>

[4879 byte] By [drifterbara] at [2007-10-2 10:50:36]
# 1

Well, I can't really read your code since it scrolls off the monitor. But, in general

a) if you can to change the data in an existing cell, just use table.setValueA(...);

b) if you want to change data in the entire TableModel then use:

DefaultTableModel model = new DefaultTableModel(....);

table.setModel( model );

camickra at 2007-7-13 3:08:42 > top of Java-index,Desktop,Core GUI APIs...