jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem selecting JList item" Watch "problem selecting JList item" New topic

problem selecting JList item

kalpana s

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;
component= (Component)value;
component.setBackground (isSelected ? new Color(51, 0, 153) : new Color(204,204,204));
return component;

kalpana s

Joined: Dec 22, 2003
Posts: 8
please just ignore the code which i have given
Don't get me started about those stupid light bulbs.
subject: problem selecting JList item
It's not a secret anymore!