Question

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 ?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top