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.addListSelectionListener( new ListSelectionListener()
            {
                  public void valueChanged(ListSelectionEvent event)
                  {
                        
                        if (event.getValueIsAdjusting()) return;

                        JList theList = (JList) event.getSource();
                  
                       
                              switch(theList.getSelectedIndex())
                              {
                                    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
Jasbir21Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimYatesCommented:
Not sure I 100% understand you, but do you mean doing something like:

    list.revalidate();
    list.repaint();

?
0
gauravkrtomarCommented:
try repainting the JList.
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
0
gauravkrtomarCommented:
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.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Jasbir21Author Commented:
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...

0
Jasbir21Author Commented:
i do have :

container.add(chartPanel);
            container.validate();  
            container.repaint();

in the switch case of the program...
0
TimYatesCommented:
>> 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
0
gauravkrtomarCommented:
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.
0
Jasbir21Author Commented:
--->>>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.
0
TimYatesCommented:
>> I am not sure but i think JList has by default 0 index selected try setting it to -1.

That should do it... ;-)
0
Jasbir21Author Commented:
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);
0
gauravkrtomarCommented:
no, i have checked it out setting index to -1 it does not work ;). Coz let say u selected index 3 then selecting index -1 will cause the method to retunr without any effect.

rather u can try a method list.clearSelection(), it deselects the selected element, this method solves the problem of list having 0 index element selected.

And just before you are returning from the method run after clicking on the button try
list.setEnabled(true);
list.setSelectedIndex(0);
list.repaint();

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gauravkrtomarCommented:
this adds the propertylistener which listens to the enabled property

dataList.addPropertyChangeListener(new PropertyChangeListener() {

                  public void propertyChange(PropertyChangeEvent evt) {
                        if(evt.getPropertyName().equals("enabled")){
                              //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
                        }

                  }

            });
0
Jasbir21Author Commented:
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...
0
Jasbir21Author Commented:
it works with clearselection..thanks..
0
Jasbir21Author Commented:
as well with repaint now...thanks
0
gauravkrtomarCommented:
>>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.
0
Jasbir21Author Commented:
what is clearCache() for ?
0
Jasbir21Author Commented:
i get error with Jlist ...

thanks for helping solving ..it works with clearselection and repaint...

btw..whats clearCache()n for
0
gauravkrtomarCommented:
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 ;)
0
Jasbir21Author Commented:
no problem...thanks for helping :-)
0
gauravkrtomarCommented:
:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.