• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem selecting JList item

 
kalpana s
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

i have a JList in my application. ihave set a definite size to the jlist.
suppose i have only 2 items on the jlist, the 2 list items will be filled only in top portion of the jlist
the remaining portion will be empty.

my problem is

when i click on the empty portion of the jlist, the last item on the jlist will get selected. i dont wnat this to happen. The item should be selected only when i clik on the jlist item not on the empty portion of the jlist.

how do i do this

The code which does the selection is as below

public class CustomCellRenderer implements ListCellRenderer
{
DefaultListCellRenderer listCellRenderer = new DefaultListCellRenderer();
public Component getListCellRendererComponent(
JList list, Object value, int index, boolean isSelected, boolean hasFocus)
{
Component component=null;
if(value!=null){
component= (Component)value;
component.setBackground (isSelected ? new Color(51, 0, 153) : new Color(204,204,204));
}
return component;
}
}


Thanks
kalpana
 
kalpana s
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please just ignore the code which i have given
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic