I have added few images to my JList showing them horizontally.
Now I want to increase the space between the images in the JList.
Could anyone suggest how to do it?
and how to set size of JList. You can use JList#setVisibleRowCount to affect the the number of visible rows the JList would like to show when wrapped in a JList .
Multiple selection list enables the user to select many items from a JList. A SINGLE_INTERVAL_SELECTION list allows selection of a contiguous range of items in the list by clicking the first item, then holding the Shift key while clicking the last item to select in the range.
JList doesn't support scrolling directly. To create a scrolling list you make the JList the viewport view of a JScrollPane.
Provide your own ListCellRenderer
which can introduce, e.g., an empty border with a specific width.
Set a fixed width and height for your JList items.
list.setFixedCellHeight(50);
list.setFixedCellWidth(100);
The setBorder()
method is for setting border insets. You can also add it to the lines above to make margin spaces arranged:
list.setBorder(new EmptyBorder(10,10, 10, 10));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With