Re: Displaying default item in empty JList
- From: "Andrey Kuznetsov" <spam0@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 30 Mar 2006 00:13:09 +0200
[...]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
.
- References:
- Displaying default item in empty JList
- From: Per E
- Re: Displaying default item in empty JList
- From: Oliver Wong
- Re: Displaying default item in empty JList
- From: Vova Reznik
- Re: Displaying default item in empty JList
- From: Oliver Wong
- Displaying default item in empty JList
- Prev by Date: Re: Gui Interface
- Next by Date: Re: JTable Display doesn't match TableModel ??
- Previous by thread: Re: Displaying default item in empty JList
- Next by thread: Re: Displaying default item in empty JList
- Index(es):
Relevant Pages
|