Jasbir21
asked on
Urgent-JList -not hearing
Hi,
I hope i am explaining alright...
But this what i have:
I have
worker = new SwingWorker()
{
does a lot of calculations..
....
list.setEnabled(true);
return doWork();
}
};
progressBar.setValue(0);
worker.start();
list.setEnabled(false);
list.setSelectedIndex(0);
list.addListSelectionListe ner( new ListSelectionListener()
{
public void valueChanged(ListSelection Event event)
{
if (event.getValueIsAdjusting ()) return;
JList theList = (JList) event.getSource();
switch(theList.getSelected Index())
{
case 0:
.....
my problem is that the list is not sensitif, once i press the run button, i need to go to list to refresh..
meaning that i thought when i put the list.setSelectedIndex(0) and when the thread ends it needs to go to updated..how to make the list to hear and get automatically updated...
maybe something like..
if(setEnabled(true))
list.setSelectedIndex(0)
but i get error...pls help.thanks
Pls help..thanks
I hope i am explaining alright...
But this what i have:
I have
worker = new SwingWorker()
{
does a lot of calculations..
....
list.setEnabled(true);
return doWork();
}
};
progressBar.setValue(0);
worker.start();
list.setEnabled(false);
list.setSelectedIndex(0);
list.addListSelectionListe
{
public void valueChanged(ListSelection
{
if (event.getValueIsAdjusting
JList theList = (JList) event.getSource();
switch(theList.getSelected
{
case 0:
.....
my problem is that the list is not sensitif, once i press the run button, i need to go to list to refresh..
meaning that i thought when i put the list.setSelectedIndex(0) and when the thread ends it needs to go to updated..how to make the list to hear and get automatically updated...
maybe something like..
if(setEnabled(true))
list.setSelectedIndex(0)
but i get error...pls help.thanks
Pls help..thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I dont think revalidate() is neede, u need to call it on the container only when the container's layout or the childs has changed and you need to recalculate everything, otherwise repaint() is sufficient. And in this case u dont need to calculate the rendering of the list from scratch.
ASKER
actually, this program is pretty long..it is a simulation program ..
what happens, is that while the program is running the list would be setEnabled false.
once the program is runned the list would be setEnabled true...
what i am trying to do is that if the setEnabled becames true..then list.setEnabledIndex(0)
however, now what is happening is that , even before i run the program, the list.setEnabledIndex(0) is highlighted...
what happens, is that while the program is running the list would be setEnabled false.
once the program is runned the list would be setEnabled true...
what i am trying to do is that if the setEnabled becames true..then list.setEnabledIndex(0)
however, now what is happening is that , even before i run the program, the list.setEnabledIndex(0) is highlighted...
ASKER
i do have :
container.add(chartPanel);
container.validate();
container.repaint();
in the switch case of the program...
container.add(chartPanel);
container.validate();
container.repaint();
in the switch case of the program...
>> even before i run the program
before you run the program?
Or before you click the button?
Can you explain what it is you want?
You want the list to have nothing selected?
Tim
before you run the program?
Or before you click the button?
Can you explain what it is you want?
You want the list to have nothing selected?
Tim
I am not sure but i think JList has by default 0 index selected try setting it to -1.
just a wild guess ;) not sure if it works.
just a wild guess ;) not sure if it works.
ASKER
--->>>before you run the program?
---->>>Or before you click the button?
Yeah..before i click the button..
what i want is that , before i run the button, nothing should be selected...
and when the run is finished, the list.setEnabled becames true, select the the first option that is O.
---->>>Or before you click the button?
Yeah..before i click the button..
what i want is that , before i run the button, nothing should be selected...
and when the run is finished, the list.setEnabled becames true, select the the first option that is O.
>> I am not sure but i think JList has by default 0 index selected try setting it to -1.
That should do it... ;-)
That should do it... ;-)
ASKER
actually, the default 0 should only be selected once the setEnabled becames true...
tried the list.setSelectedIndex(-1) but did not get index 0.
actually, index 0 works for the first option...
my problem is that i would need to refresh the list to see the result(For example, clicking the option....
i think, maybe once the list becames enabled, then set it index is 0 ..
because when the list is enabled, it means,that all calculations are ready to be displayed...
is there such thing as ...
if(setEnabled becomes true)
llist.setSelectedIndex(0);
tried the list.setSelectedIndex(-1) but did not get index 0.
actually, index 0 works for the first option...
my problem is that i would need to refresh the list to see the result(For example, clicking the option....
i think, maybe once the list becames enabled, then set it index is 0 ..
because when the list is enabled, it means,that all calculations are ready to be displayed...
is there such thing as ...
if(setEnabled becomes true)
llist.setSelectedIndex(0);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
this adds the propertylistener which listens to the enabled property
dataList.addPropertyChange Listener(n ew PropertyChangeListener() {
public void propertyChange(PropertyCha ngeEvent evt) {
if(evt.getPropertyName().e quals("ena bled")){
//u will get the Boolean tr
Boolean newValue=(Boolean) evt.getNewValue();
Boolean oldValue=(Boolean) evt.getNewValue();
// do whatever u want to do depending upon the newValue and oldValue
}
}
});
dataList.addPropertyChange
public void propertyChange(PropertyCha
if(evt.getPropertyName().e
//u will get the Boolean tr
Boolean newValue=(Boolean) evt.getNewValue();
Boolean oldValue=(Boolean) evt.getNewValue();
// do whatever u want to do depending upon the newValue and oldValue
}
}
});
ASKER
list.setEnabled(true);
list.setSelectedIndex(0);
list.repaint();
when i try the above, the first run it gets updates...but when i press the run button again, it does update...
list.setSelectedIndex(0);
list.repaint();
when i try the above, the first run it gets updates...but when i press the run button again, it does update...
ASKER
it works with clearselection..thanks..
ASKER
as well with repaint now...thanks
>>when i try the above, the first run it 'gets' updates...
>>but when i press the run button again, it 'does' update..
i am not able to get the difference b/w get and does.
Plus look at the above code for the listener, i think it does solve one of ur problems.
Also keep in mind:-
list.clearCache();
list.setSelectedIndex() but only after list.setEnabled(true)
and list.repaint() if u want to render the list.
>>but when i press the run button again, it 'does' update..
i am not able to get the difference b/w get and does.
Plus look at the above code for the listener, i think it does solve one of ur problems.
Also keep in mind:-
list.clearCache();
list.setSelectedIndex() but only after list.setEnabled(true)
and list.repaint() if u want to render the list.
ASKER
what is clearCache() for ?
ASKER
i get error with Jlist ...
thanks for helping solving ..it works with clearselection and repaint...
btw..whats clearCache()n for
thanks for helping solving ..it works with clearselection and repaint...
btw..whats clearCache()n for
sorry actually it was a typo mistake.............I was writting clearSelection only but wrote clearCache(), i was doing some dbase things so i wrote that instead ;)
ASKER
no problem...thanks for helping :-)
:)
As after updating any component u need to repaint it so that the effect is visible. After your thread finishes u can do list.repaint().
P.S.:- Can u post ur code with a bit of more clarifications as it is still not clear