Re: Displaying default item in empty JList



I use a JList to display contents that change dynamically. At certain
times,
there are no entries at all in the list and I would like the JList
display a
default string (like "-empty list-") and be disabled. I have a working
fix
where the model and controller takes care of supplying the "empty list"
functionality, but think that following MVC practive, it should be the
responsibility of the JList to figure this out by itself. However, I am
completely stuck as how to alter the standard JList behaviour to fit my
requirements.
[...]

If "-empty list-" is just default item in a JList when list is empty
than, following MVC, it should be model responsibility. So right approach
is creating custom ListModel that will take care.

I'm not sure about this. The fact that the string "-empty list-"
appears visually seems to have to do with the View, and not the Model.
E.g., if a different view (perhaps an XML based one) were available, it
might not want to display "-empty list-" as one of the items in the list.
Or if you had a view which was the front-end to an AI program that looked
at the list and behaved depending on its contents, you might not want for
that AI to see the string "-empty list-" either.

I agree, the model is wrong place.
Probably he should just paint string "-empty list-" just after
backgound was painted, but before cells are rendered.

However, if it is also possible (and also easyer) to make it with model.
For example one could write ListCellRenderer which renders first element
with height = 0 if there are more then 1 element.

Andrey

--
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities


"Oliver Wong" <owong@xxxxxxxxxxxxxx> schrieb im Newsbeitrag
news:nnDWf.16452$K11.12856@xxxxxxxxxxx
"Vova Reznik" <address@xxxxxxxx> wrote in message
news:X3DWf.43278$_S7.1969@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
"Per E" <hasselbld@xxxxxxxxx> wrote in message
news:ZX9Wf.50098$d5.206559@xxxxxxxxxxxxxxxxxx
Dear all,


My interpretation is that "-empty list-" is just to make the JList look
prettier; if the "-empty list-" item is actually part of the model,
though, then of course it should be part of the model.

- Oliver


.



Relevant Pages

  • Re: Inflexible array members
    ... allows VB programmers to write rubbish VB, Java programmers to write ... rubbish Java, and managers to write rubbish reports. ... runtime overhead implications and yet you still didn't care. ...
    (comp.lang.c)
  • Re: Java 7 features
    ... of new Java 7 features. ... @ Language-level XML support ... Don't care. ... One thing I would like to see is very tight integration with Linux. ...
    (comp.lang.java.programmer)
  • Re: new to programming in Linux
    ... > What I am really after is an IDE like VB6, that takes care of drawing the ... > write good, fast programs in Java? ... fast program in Java someone gave it the comment "perverse ...
    (comp.os.linux.development.apps)
  • Re: VM problem!! What ever that is!!
    ... Take care and have a great week ahead!!! ... >Check your control panel for a java applet--You may need ... >> Hi Juan, See my attach file for the message I get. ... >> updates and it says I have all the newest updates and ...
    (microsoft.public.security)