tags:

views:

220

answers:

1

My application is using a JList to display numerical values.

Here is the default display :

+-----------------+
|value 1          |
|value 2          |
|value 3          |
|                 |
|                 |
|                 |
|                 |
+-----------------+

I would like to change the vertical alignement, so that the values are display at the bottom right of the frame, like this :

+-----------------+
|                 |
|                 |
|                 |
|                 |
|          value 1|
|          value 2|
|          value 3|
+-----------------+

If a new element is added, it should be displayed at the bottom :

+-----------------+
|                 |
|                 |
|                 |
|          value 1|
|          value 2|
|          value 3|
|          value 4|
+-----------------+

The list is inside a JScrollPane, to limit the number of element displayed.

Is it doable ? Or do I have to use another component ?

+1  A: 

As a hack maybe you can play with the Border of the JList. When the list is empty you size the Border to take up all the space of the list. When you add a row you decrease the Border.top insets by the row size.

camickr
Changing the Border size according to the number of elements in the list works, I just had to add a ListDataListener to react to any change in the model.I'm still struggling with window resizing though : I haven't found a way to correctly adapt the border size when the window displaying the list is being resized.
Jérôme