MenuItemDiabled.java Source code

Java tutorial

Introduction

Here is the source code for MenuItemDiabled.java

Source

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

public class MenuItemDiabled {
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new GridLayout());

        Menu menuBar = new Menu(shell, SWT.BAR);

        Menu fileMenu = new Menu(menuBar);

        MenuItem fileItem = new MenuItem(menuBar, SWT.CASCADE | SWT.NO_RADIO_GROUP);
        fileItem.setText("File");
        fileItem.setMenu(fileMenu);

        MenuItem itema = new MenuItem(fileMenu, SWT.NONE);
        itema.setText("Radio A");
        itema.setEnabled(false);
        MenuItem itemb = new MenuItem(fileMenu, SWT.NONE);
        itemb.setText("Radio B");
        MenuItem itemc = new MenuItem(fileMenu, SWT.NONE);
        itemc.setText("Radio C");

        shell.setMenuBar(menuBar);
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }
}