Java Swing: JList with ListCellRenderer selected item different height

前端 未结 7 1621
花落未央
花落未央 2020-12-17 05:27

I\'m making a custom ListCellRenderer. I know that you can have different dimensions for each individual cell. But now I want to have a different dimension for the selected

7条回答
  •  情书的邮戳
    2020-12-17 05:52

    The JList has no ability to change size of cell depending on selection or whatever. The list use "cached" sizes. If there is new cellRenderer provided this sizes are recounted and applied within all cells in list. I think the reason is performance for list with a lot of entries. The possible solution is to write own ListUI implementation which is able to use different sizes for selected and unselected cells. This brings also possibility to adjust size of cells around selection by logarithm or other interpolation. I hope you have a big reason why to do this. It is a lot of work!

提交回复
热议问题