Results 1 to 4 of 4
- 03-23-2010, 09:35 AM #1
Member
- Join Date
- Apr 2009
- Posts
- 29
- Rep Power
- 0
Problem in row selection in JTable
Hi,
I have a Jtable in my application. For its cell rendering I have created a class which extends DefaultTableCellRenderer and overridden the method getTableCellRendererComponent. I am trying to change the background color of a particular column based on its value. But after doing that when I select a row its selection is not visible to me. Row is getting selected as the action on row selection is working properly but selection is not visible to me(selected row is not getting highlighted).
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int col) {
Component comp = super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, col);
TableModel fm = table.getModel();
if(col == 5 &&
((fm.getValueAt(row, col).toString().trim()).equals("abc"))){
comp.setBackground(Color.LIGHT_GRAY);
}
else{
comp.setBackground(Color.WHITE);
}
return comp;
}
This seems to be happening because of "comp.setBackground(Color.WHITE);" in else condition. But if I remove else condition then background color of all the columns after 5th column of first row gets changed. Color of viewport of Jscrollpane of Jtbale is WHITE so I am setting the color to white in else condition.
What should I do to see the selection.
Thanks in Advance,
Simmi
- 03-23-2010, 12:14 PM #2
Did you notice that one of the parameters to the method you are overriding is boolean isSelected? Make good use of it.
db
- 03-23-2010, 12:35 PM #3
Member
- Join Date
- Apr 2009
- Posts
- 29
- Rep Power
- 0
Yeah...I used if(!isSelected) and it worked.
Thanks
- 03-23-2010, 04:30 PM #4
Similar Threads
-
Jtable selection question
By casid in forum New To JavaReplies: 2Last Post: 02-04-2010, 07:11 PM -
Jtable Column Selection Problem
By REVANSIDDHA in forum Advanced JavaReplies: 0Last Post: 03-31-2009, 07:53 AM -
Problem in JTable row selection
By shanssat in forum AWT / SwingReplies: 1Last Post: 02-04-2009, 07:50 AM -
Multiple selection on JTable
By hendrix79 in forum New To JavaReplies: 2Last Post: 01-30-2009, 06:11 PM -
JTable Combo Box Row Selection Problem
By hemanthjava in forum AWT / SwingReplies: 2Last Post: 12-18-2008, 07:31 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks