Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get custom space between Jlist item?

Tags:

java

swing

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?

like image 522
Jony Avatar asked Mar 08 '12 12:03

Jony


People also ask

How do I set the size of a JList?

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 .

How do I select multiple items in 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.

Is JList scrollable?

JList doesn't support scrolling directly. To create a scrolling list you make the JList the viewport view of a JScrollPane.


2 Answers

Provide your own ListCellRenderer which can introduce, e.g., an empty border with a specific width.

like image 32
stryba Avatar answered Sep 18 '22 08:09

stryba


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));
like image 177
Juvanis Avatar answered Sep 18 '22 08:09

Juvanis