I’d like to be able to display a mutable list (using Swing) such that the first item is at the bottom in a fixed position, and subsequent items appear above it. Just the way a stack of stuff would appear in reality. The behavior is that of a FIFO queue (add to the top, remove from the bottom).
I can imagine a solution involving “padding” the list and then sorting it in reverse, or something like that, but I wondered if there might be a more direct way.
Example:
item[0]="Adam"
item[1]="Baker"
item[2]="Charlie"
should appear in 5-row list as:
+----------
|
|
| Charlie
| Baker
| Adam
+----------
If you don’t want to create a custom model, then you can use the DefaultListModel. Then instead of using:
you can use:
and the elements will be displayed in the order you wish.
The following code also show how you might make the list look bigger than it really is: