Re: How to add elements to a JList without preventing refresh



Anonymous user wrote:
Thomas Hawtin a écrit :


Anonymous user wrote:

i have a simple problem. Let's say that in some app, i have a loop wich
add a lot of elements to a JList. I CANNOT change the loop, but i can
change how each element is added.

Are you not going to tell us why?


Because i'm working on JTable and sometimes, the same error happens for
all the cells in a column for example. If the error happens in the
renderering (TableCellRenderer) then you have some kind of loop that
you can't control.

So the body of the loop sometime throws an exception, in which case no more entries should be added? That doesn't stop you doing the loop differently. Perhaps in sections. Perhaps in a different thread (but not directly accessing Swing components).


For this problem and all the ones conerning the build of the frame,
blame Eclipse Visual Editor.

I blame using a GUI builder.

good idea, i fill up a regular List, and in paintComponent(), i do:

Not necessarily paintComponent. The effect will be much the same, although it might flash if you do do it from the paint.


An anonymous inner class would have worked better here.


i don't know how add a parameter to the constructor in anonymous inner
class

Make a local variable final in the enclosing method. You can the access it from within the anonymous inner class.


You need the standard boilerplate here:

EventQueue.invokeLater(new Runnable() { public void run() {

i've never managed to understand why it is needed, so i never write
it...

Take it on trust...

The main thread is different from the AWT Event Dispatch Thread (EDT). If you don't transfer across to the EDT then you have a multithreaded Swing program! You'll be okay most of the time. Most of the time.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
.



Relevant Pages

  • Anonymous inner classes
    ... I have an anonymous inner class in my code which is getting ... public Image getImage() { ... I have a client code which calls the method getImagein a for loop ... The reason I thought of using is I am not changing the Image ...
    (comp.lang.java.programmer)
  • Re: Anonymous inner classes
    ... On Tue, 6 May 2008, Vikram wrote: ... public Image getImage() { ... I have a client code which calls the method getImagein a for loop ... That doesn't sound like a great reason to use an anonymous inner class. ...
    (comp.lang.java.programmer)