📄 e775. setting the dimensions of an item in a jlist component.txt
字号:
By default, the width of the list is determined by the longest item and the height is determined by the number of visible lines multiplied by the tallest item. This example demonstrates how to override these values.
// Create a list
String[] items = {"A", "B", "C", "D"};
JList list = new JList(items);
// Set the item width
int cellWidth = 200;
list.setFixedCellWidth(cellWidth);
// Set the item height
int cellHeight = 18;
list.setFixedCellHeight(cellHeight);
It is also possible to set the item dimensions using a sample value:
String protoCellValue = "My Sample Item Value";
list.setPrototypeCellValue(protoCellValue);
Related Examples
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -