valleytech
asked on
Jlist
when user select one item on JList, I can obtain selection by:
String input= jList.getSelectedValue().t oString();
However, I want to get the first item on the Jlist if user doesn't
make any selection. Thanks.
String input= jList.getSelectedValue().t
However, I want to get the first item on the Jlist if user doesn't
make any selection. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
how can it can't take the value when i click on scrollpane without clicking on the text inside Jlist?? The Jlist display only one row at a time.
> softwareJList.setSelectedI ndex(0);
you would only do that if you actually wanted to select the first item
you would only do that if you actually wanted to select the first item
the code i posted above does not rely on the seledtion , it just returns the first element
ASKER
so please help me on select the item either user click on item or just scroll down. JList can display one row at a time.
jList.ensureIndexIsVisible (0);
ASKER
My Jlist has a scrollpane and can display one row at a time.
when user doesn't do anything, it will select first item of the list. Work perfectly.
However, when user roll down scrollpane to make a selection on JList:
+ if he click on the item. Work perfectly
+ if he is lazy to click on item, DOESN't work.
Please help.
when user doesn't do anything, it will select first item of the list. Work perfectly.
However, when user roll down scrollpane to make a selection on JList:
+ if he click on the item. Work perfectly
+ if he is lazy to click on item, DOESN't work.
Please help.
> + if he is lazy to click on item, DOESN't work.
So you want to select the visible item even if they don't click. Is that correct?
When would it change the selection?
Why not use a JComboBox instead?
So you want to select the visible item even if they don't click. Is that correct?
When would it change the selection?
Why not use a JComboBox instead?
ASKER
yeSo you want to select the visible item even if they don't click. Is that correct? <-- that's true.
I start by jlist so i get stuck with it. hic hic.
I start by jlist so i get stuck with it. hic hic.
cause the user may just have scrolled down to look at other options available and does not want to select the visible item.
What you are trying to do sort of breaks ui guidelines
What you are trying to do sort of breaks ui guidelines
ASKER
I see. So i better change to combobox?
ASKER
before i change to combobox, i just wonder whether i can display only 1 item at a time in comboBox?
a combo only display ones at a time, it uses a pull down to change the displayed item
http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html
http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html
ASKER
and same problem. How to get first item if user is lazy to select item within combo box> thanks a lot.
they cannot be lazy with a combo, only the selected item will be displayed
ASKER
cool. let me close this. please help me on GUI question.
ASKER
softwareJList.setSelectedI
inputSoftwareText = softwareJList.getSelectedV