Java JList.setFixedCellWidth(int width)

Syntax

JList.setFixedCellWidth(int width) has the following syntax.

public void setFixedCellWidth(int width)

Example

In the following code shows how to use JList.setFixedCellWidth(int width) method.


import javax.swing.JList;
/*  ww w. ja  va2s  .c om*/
public class Main {
  public static void main(String[] argv) throws Exception {
    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);

  }
}