Esempio n. 1
0
 public int[] getSelectedIndexes() {
   List l = (List) target;
   int len = l.countItems();
   int sel[] = new int[len];
   int nsel = 0;
   for (int i = 0; i < len; i++) {
     if (isSelected(i)) {
       sel[nsel++] = i;
     }
   }
   int selected[] = new int[nsel];
   System.arraycopy(sel, 0, selected, 0, nsel);
   return selected;
 }
Esempio n. 2
0
  void initialize() {
    List li = (List) target;

    fm = getFontMetrics(li.getFont());

    Font font = li.getFont();
    if (font != null) setFont(font);

    // add any items that were already inserted in the target.
    int nitems = li.countItems();
    if (nitems > 0) {
      String[] items = new String[nitems];
      int maxWidth = 0;
      int width = 0;
      for (int i = 0; i < nitems; i++) {
        items[i] = li.getItem(i);
        width = fm.stringWidth(items[i]);
        if (width > maxWidth) {
          maxWidth = width;
        }
      }
      addItems(items, 0, maxWidth);
    }

    // set whether this list should allow multiple selections.
    setMultipleSelections(li.allowsMultipleSelections());

    // select the item if necessary.
    int sel[] = li.getSelectedIndexes();
    for (int i = 0; i < sel.length; i++) {
      select(sel[i]);
    }

    // make the visible position visible.
    // fix for 4676536 by [email protected]
    // we should call makeVisible() after we call select()
    // because of a bug in Windows which is manifested by
    // incorrect scrolling of the selected item if the list
    // height is less than an item height of the list.
    int index = li.getVisibleIndex();
    if (index < 0 && sel.length > 0) {
      index = sel[0];
    }
    if (index >= 0) {
      makeVisible(index);
    }

    super.initialize();
  }
Esempio n. 3
0
 public void clear() {
   List l = (List) target;
   delItems(0, l.countItems());
 }