aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes problem selecting JList item Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem selecting JList item" Watch "problem selecting JList item" New topic
Author

problem selecting JList item

kalpana s
Greenhorn

Joined: Dec 22, 2003
Posts: 8
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

Joined: Dec 22, 2003
Posts: 8
please just ignore the code which i have given
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem selecting JList item