Skip to main content

Problem selecting single cell in a Jtable filled with Jlabels

No replies
vspadaro
Offline
Joined: 2008-02-10
Points: 0

Hi All,

i have a big problem trying to develop a complex jtable.

My objective was to have a Jtable that contains in iterative mode an Icon image into a row and a text into the row below in order to simulate a grid with file name and related icon.
My render will return for both cases a JLabel as shown:

private class IconTableCellRenderer extends DefaultTableCellRenderer {
public IconTableCellRenderer()
{
setHorizontalAlignment( CENTER );
}
public Component getTableCellRendererComponent(JTable table, Object value
, boolean isSelected, boolean hasFocus, int row, int column) {
JLabel jlb;
for (int i = 0; i <= row; i++)
{
if ((row%2) != 0)
{
jlb = new JLabel((String)value); jlb.setHorizontalAlignment(CENTER);
return jlb;
}
else
return new JLabel((ImageIcon)value);
}return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}

the problem is that if I wanf to select a cell and doing some action when I click on it No cell is selected or hilighted.

Could Someone help me to solve this bloking point?

Thanks in advance
with my best regards
VAlerio

Message was edited by: vspadaro