Java Code Examples for javax.swing.JList#setFixedCellWidth()

The following examples show how to use javax.swing.JList#setFixedCellWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListSelector.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Instantiates a new list selector.
 *
 * @param listData the list data
 */
public ListSelector(Object[] listData) {
  for (int i = 0; i < listData.length; i++)
    listModel.addElement(listData[i]);

  setLayout(new BorderLayout(4, 4));
  list = new JList(listModel);
  list.setFixedCellWidth(200);
  list.setVisibleRowCount(3);
  list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  Border etchedBorder = BorderFactory.createEtchedBorder();
  list.setBorder(etchedBorder);

  JScrollPane scrollPane = new JScrollPane(list, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
          ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
  add(scrollPane, BorderLayout.CENTER);

  JPanel controlPanel = new JPanel();
  GridBagLayout gbl = new GridBagLayout();
  GridBagConstraints gbc = new GridBagConstraints();
  gbc.insets = new Insets(2, 2, 2, 2);
  controlPanel.setLayout(gbl);

  addField = new JTextField(6);
  addField.addActionListener(this);

  gbc.gridx = 0;
  gbc.gridy = 0;
  gbc.anchor = GridBagConstraints.NORTHEAST;
  controlPanel.add(addField, gbc);

  gbc.gridx = 1;
  gbc.anchor = GridBagConstraints.NORTHWEST;

  addButton = new SmallButton("Add");
  addButton.addActionListener(this);
  controlPanel.add(addButton, gbc);

  gbc.gridx = 0;
  gbc.gridy = 1;
  gbc.anchor = GridBagConstraints.WEST;

  JPanel movePanel = new JPanel();
  movePanel.setLayout(new GridLayout(1, 2, 4, 4));

  moveUpButton = new ImageButton(Images.UP);
  moveUpButton.addActionListener(this);
  movePanel.add(moveUpButton);

  moveDownButton = new ImageButton(Images.DOWN);
  moveDownButton.addActionListener(this);
  movePanel.add(moveDownButton);

  controlPanel.add(movePanel, gbc);

  gbc.gridx = 1;
  gbc.anchor = GridBagConstraints.WEST;

  gbc.anchor = GridBagConstraints.WEST;
  removeButton = new SmallButton("Remove");
  removeButton.addActionListener(this);
  controlPanel.add(removeButton, gbc);

  add(controlPanel, BorderLayout.EAST);
}