简体   繁体   English

如何在Jlist项目之间获得自定义空间?

[英]How to get custom space between Jlist item?

I have added few images to my JList showing them horizontally. 我在JList中添加了一些图像,水平显示它们。

Now I want to increase the space between the images in the JList. 现在我想增加JList中图像之间的空间。

Could anyone suggest how to do it? 谁能建议怎么做?

Set a fixed width and height for your JList items. 为JList项设置固定的宽度和高度。

list.setFixedCellHeight(50);
list.setFixedCellWidth(100);

The setBorder() method is for setting border insets. setBorder()方法用于设置边框insets。 You can also add it to the lines above to make margin spaces arranged: 您还可以将其添加到上面的行中以排列边距空间:

list.setBorder(new EmptyBorder(10,10, 10, 10));

提供您自己的ListCellRenderer ,它可以引入例如具有特定宽度的空边框。

there are two ways 有两种方法

1) Renderer can returns JLabel , set EmptyBorders() 1) Renderer可以返回JLabel ,设置EmptyBorders()

2) a little bit complicated way is put there JSeparator 2) JSeparator有点复杂的方式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM