Combo: setEnabled(boolean b) : Combo « org.eclipse.swt.widgets « Java by API






Combo: setEnabled(boolean b)


import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MainClass {

  public static void main(String[] a) {
    Display d = new Display();
    Shell s = new Shell(d);

    s.setSize(250, 250);
    s.setText("A Combo Example");
    final Combo c1 = new Combo(s, SWT.READ_ONLY);
    c1.setBounds(50, 50, 150, 65);
    final Combo c2 = new Combo(s, SWT.READ_ONLY);
    c2.setBounds(50, 85, 150, 65);
    c2.setEnabled(false);
    String items[] = { "Item One", "Item Two", "Item Three", "Item Four", "Item Five" };
    c1.setItems(items);
    c1.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {
        if (c1.getText().equals("Item One")) {
          String newItems[] = { "A", "B", "C" };
          c2.setItems(newItems);
          c2.setEnabled(true);
        } else if (c1.getText().equals("Item Two")) {
          String newItems[] = { "A", "B", "C" };
          c2.setItems(newItems);
          c2.setEnabled(true);
        } else {
          c2.add("Not Applicable");
          c2.setText("Not Applicable");
        }
      }
    });
    s.open();
    while (!s.isDisposed()) {
      if (!d.readAndDispatch())
        d.sleep();
    }
    d.dispose();
  }
}

           
       








Related examples in the same category

1.new Combo(Shell shell, SWT.DROP_DOWN)
2.new Combo(Shell shell, SWT.DROP_DOWN | SWT.READ_ONLY)
3.new Combo(Shell shell, SWT.SIMPLE)
4.new Combo(Composite parent, int style)(SWT.DROP_DOWN | SWT.BORDER)
5.new Combo(Shell s, SWT.READ_ONLY)
6.Combo: add(String sel)
7.Combo: addSelectionListener(SelectionListener lis)
8.Combo: getItems()
9.Combo: getText()
10.Combo: select(int index)
11.Combo: setItems(String[] values)