[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Urgent-JList -not hearing

Posted on 2006-04-13
21
Medium Priority
?
451 Views
Last Modified: 2008-03-03
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
0
Comment
Question by:Jasbir21
  • 10
  • 8
  • 3
21 Comments
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 240 total points
ID: 16443877
Not sure I 100% understand you, but do you mean doing something like:

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

?
0
 
LVL 2

Expert Comment

by:gauravkrtomar
ID: 16443883
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
 
LVL 2

Expert Comment

by:gauravkrtomar
ID: 16443903
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Jasbir21
ID: 16443914
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
 

Author Comment

by:Jasbir21
ID: 16443920
i do have :

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

in the switch case of the program...
0
 
LVL 35

Expert Comment

by:TimYates
ID: 16443923
>> 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
 
LVL 2

Expert Comment

by:gauravkrtomar
ID: 16443968
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
 

Author Comment

by:Jasbir21
ID: 16443975
--->>>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
 
LVL 35

Expert Comment

by:TimYates
ID: 16444005
>> I am not sure but i think JList has by default 0 index selected try setting it to -1.

That should do it... ;-)
0
 

Author Comment

by:Jasbir21
ID: 16444024
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
 
LVL 2

Accepted Solution

by:
gauravkrtomar earned 360 total points
ID: 16444027
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
 
LVL 2

Expert Comment

by:gauravkrtomar
ID: 16444064
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
 

Author Comment

by:Jasbir21
ID: 16444105
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
 

Author Comment

by:Jasbir21
ID: 16444117
it works with clearselection..thanks..
0
 

Author Comment

by:Jasbir21
ID: 16444123
as well with repaint now...thanks
0
 
LVL 2

Expert Comment

by:gauravkrtomar
ID: 16444126
>>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
 

Author Comment

by:Jasbir21
ID: 16444156
what is clearCache() for ?
0
 

Author Comment

by:Jasbir21
ID: 16444159
i get error with Jlist ...

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

btw..whats clearCache()n for
0
 
LVL 2

Expert Comment

by:gauravkrtomar
ID: 16444234
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
 

Author Comment

by:Jasbir21
ID: 16444270
no problem...thanks for helping :-)
0
 
LVL 2

Expert Comment

by:gauravkrtomar
ID: 16444369
:)
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month18 days, 8 hours left to enroll

826 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question