Example usage for java.awt Frame add

List of usage examples for java.awt Frame add

Introduction

In this page you can find the example usage for java.awt Frame add.

Prototype

public Component add(Component comp) 

Source Link

Document

Appends the specified component to the end of this container.

Usage

From source file:org.eclipse.swt.snippets.Snippet155.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 155");
    shell.setLayout(new FillLayout());
    Composite composite = new Composite(shell, SWT.EMBEDDED);

    /* Draw an X using AWT */
    Frame frame = SWT_AWT.new_Frame(composite);
    Canvas canvas = new Canvas() {
        @Override//from   w w  w  . j  a  va2s.c o  m
        public void paint(Graphics g) {
            Dimension d = getSize();
            g.drawLine(0, 0, d.width, d.height);
            g.drawLine(d.width, 0, 0, d.height);
        }
    };
    frame.add(canvas);

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

From source file:org.eclipse.swt.snippets.Snippet154.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 154");
    shell.setLayout(new FillLayout());

    Composite composite = new Composite(shell, SWT.NO_BACKGROUND | SWT.EMBEDDED);

    /*//from   w  ww .j  a  v  a  2 s.co m
    * Set a Windows specific AWT property that prevents heavyweight
    * components from erasing their background. Note that this
    * is a global property and cannot be scoped. It might not be
    * suitable for your application.
    */
    try {
        System.setProperty("sun.awt.noerasebackground", "true");
    } catch (NoSuchMethodError error) {
    }

    /* Create and setting up frame */
    Frame frame = SWT_AWT.new_Frame(composite);
    Panel panel = new Panel(new BorderLayout()) {
        @Override
        public void update(java.awt.Graphics g) {
            /* Do not erase the background */
            paint(g);
        }
    };
    frame.add(panel);
    JRootPane root = new JRootPane();
    panel.add(root);
    java.awt.Container contentPane = root.getContentPane();

    /* Creating components */
    int nrows = 1000, ncolumns = 10;
    Vector<Vector<String>> rows = new Vector<>();
    for (int i = 0; i < nrows; i++) {
        Vector<String> row = new Vector<>();
        for (int j = 0; j < ncolumns; j++) {
            row.addElement("Item " + i + "-" + j);
        }
        rows.addElement(row);
    }
    Vector<String> columns = new Vector<>();
    for (int i = 0; i < ncolumns; i++) {
        columns.addElement("Column " + i);
    }
    JTable table = new JTable(rows, columns);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.createDefaultColumnsFromModel();
    JScrollPane scrollPane = new JScrollPane(table);
    contentPane.setLayout(new BorderLayout());
    contentPane.add(scrollPane);

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

From source file:SystemFileTree.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);

    RGB color = shell.getBackground().getRGB();
    Label separator1 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    Label locationLb = new Label(shell, SWT.NONE);
    locationLb.setText("Location:");
    Composite locationComp = new Composite(shell, SWT.EMBEDDED);
    Label separator2 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    final Composite comp = new Composite(shell, SWT.NONE);
    final Tree fileTree = new Tree(comp, SWT.SINGLE | SWT.BORDER);
    Sash sash = new Sash(comp, SWT.VERTICAL);
    Composite tableComp = new Composite(comp, SWT.EMBEDDED);
    Label separator3 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    Composite statusComp = new Composite(shell, SWT.EMBEDDED);

    java.awt.Frame locationFrame = SWT_AWT.new_Frame(locationComp);
    final java.awt.TextField locationText = new java.awt.TextField();
    locationFrame.add(locationText);

    java.awt.Frame statusFrame = SWT_AWT.new_Frame(statusComp);
    statusFrame.setBackground(new java.awt.Color(color.red, color.green, color.blue));
    final java.awt.Label statusLabel = new java.awt.Label();
    statusFrame.add(statusLabel);/*from   w w  w .ja  va2s  .com*/
    statusLabel.setText("Select a file");

    sash.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            if (e.detail == SWT.DRAG)
                return;
            GridData data = (GridData) fileTree.getLayoutData();
            Rectangle trim = fileTree.computeTrim(0, 0, 0, 0);
            data.widthHint = e.x - trim.width;
            comp.layout();
        }
    });

    File[] roots = File.listRoots();
    for (int i = 0; i < roots.length; i++) {
        File file = roots[i];
        TreeItem treeItem = new TreeItem(fileTree, SWT.NONE);
        treeItem.setText(file.getAbsolutePath());
        treeItem.setData(file);
        new TreeItem(treeItem, SWT.NONE);
    }
    fileTree.addListener(SWT.Expand, new Listener() {
        public void handleEvent(Event e) {
            TreeItem item = (TreeItem) e.item;
            if (item == null)
                return;
            if (item.getItemCount() == 1) {
                TreeItem firstItem = item.getItems()[0];
                if (firstItem.getData() != null)
                    return;
                firstItem.dispose();
            } else {
                return;
            }
            File root = (File) item.getData();
            File[] files = root.listFiles();
            if (files == null)
                return;
            for (int i = 0; i < files.length; i++) {
                File file = files[i];
                if (file.isDirectory()) {
                    TreeItem treeItem = new TreeItem(item, SWT.NONE);
                    treeItem.setText(file.getName());
                    treeItem.setData(file);
                    new TreeItem(treeItem, SWT.NONE);
                }
            }
        }
    });
    fileTree.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            TreeItem item = (TreeItem) e.item;
            if (item == null)
                return;
            final File root = (File) item.getData();
            statusLabel.setText(root.getAbsolutePath());
            locationText.setText(root.getAbsolutePath());
        }
    });

    GridLayout layout = new GridLayout(4, false);
    layout.marginWidth = layout.marginHeight = 0;
    layout.horizontalSpacing = layout.verticalSpacing = 1;
    shell.setLayout(layout);
    GridData data;
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 4;
    separator1.setLayoutData(data);
    data = new GridData();
    data.horizontalSpan = 1;
    data.horizontalIndent = 10;
    locationLb.setLayoutData(data);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    data.heightHint = locationText.getPreferredSize().height;
    locationComp.setLayoutData(data);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 1;
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 4;
    separator2.setLayoutData(data);
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 4;
    comp.setLayoutData(data);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 4;
    separator3.setLayoutData(data);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 4;
    data.heightHint = statusLabel.getPreferredSize().height;
    statusComp.setLayoutData(data);

    layout = new GridLayout(3, false);
    layout.marginWidth = layout.marginHeight = 0;
    layout.horizontalSpacing = layout.verticalSpacing = 1;
    comp.setLayout(layout);
    data = new GridData(GridData.FILL_VERTICAL);
    data.widthHint = 200;
    fileTree.setLayoutData(data);
    data = new GridData(GridData.FILL_VERTICAL);
    sash.setLayoutData(data);
    data = new GridData(GridData.FILL_BOTH);
    tableComp.setLayoutData(data);

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

From source file:org.eclipse.swt.snippets.Snippet135.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("SWT and Swing/AWT Example");

    Listener exitListener = e -> {/*from  w w w.  j a  v a  2  s .c  o  m*/
        MessageBox dialog = new MessageBox(shell, SWT.OK | SWT.CANCEL | SWT.ICON_QUESTION);
        dialog.setText("Question");
        dialog.setMessage("Exit?");
        if (e.type == SWT.Close)
            e.doit = false;
        if (dialog.open() != SWT.OK)
            return;
        shell.dispose();
    };
    Listener aboutListener = e -> {
        final Shell s = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
        s.setText("About");
        GridLayout layout = new GridLayout(1, false);
        layout.verticalSpacing = 20;
        layout.marginHeight = layout.marginWidth = 10;
        s.setLayout(layout);
        Label label = new Label(s, SWT.NONE);
        label.setText("SWT and AWT Example.");
        Button button = new Button(s, SWT.PUSH);
        button.setText("OK");
        GridData data = new GridData();
        data.horizontalAlignment = GridData.CENTER;
        button.setLayoutData(data);
        button.addListener(SWT.Selection, event -> s.dispose());
        s.pack();
        Rectangle parentBounds = shell.getBounds();
        Rectangle bounds = s.getBounds();
        int x = parentBounds.x + (parentBounds.width - bounds.width) / 2;
        int y = parentBounds.y + (parentBounds.height - bounds.height) / 2;
        s.setLocation(x, y);
        s.open();
        while (!s.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
    };
    shell.addListener(SWT.Close, exitListener);
    Menu mb = new Menu(shell, SWT.BAR);
    MenuItem fileItem = new MenuItem(mb, SWT.CASCADE);
    fileItem.setText("&File");
    Menu fileMenu = new Menu(shell, SWT.DROP_DOWN);
    fileItem.setMenu(fileMenu);
    MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH);
    exitItem.setText("&Exit\tCtrl+X");
    exitItem.setAccelerator(SWT.CONTROL + 'X');
    exitItem.addListener(SWT.Selection, exitListener);
    MenuItem aboutItem = new MenuItem(fileMenu, SWT.PUSH);
    aboutItem.setText("&About\tCtrl+A");
    aboutItem.setAccelerator(SWT.CONTROL + 'A');
    aboutItem.addListener(SWT.Selection, aboutListener);
    shell.setMenuBar(mb);

    RGB color = shell.getBackground().getRGB();
    Label separator1 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    Label locationLb = new Label(shell, SWT.NONE);
    locationLb.setText("Location:");
    Composite locationComp = new Composite(shell, SWT.EMBEDDED);
    ToolBar toolBar = new ToolBar(shell, SWT.FLAT);
    ToolItem exitToolItem = new ToolItem(toolBar, SWT.PUSH);
    exitToolItem.setText("&Exit");
    exitToolItem.addListener(SWT.Selection, exitListener);
    ToolItem aboutToolItem = new ToolItem(toolBar, SWT.PUSH);
    aboutToolItem.setText("&About");
    aboutToolItem.addListener(SWT.Selection, aboutListener);
    Label separator2 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    final Composite comp = new Composite(shell, SWT.NONE);
    final Tree fileTree = new Tree(comp, SWT.SINGLE | SWT.BORDER);
    Sash sash = new Sash(comp, SWT.VERTICAL);
    Composite tableComp = new Composite(comp, SWT.EMBEDDED);
    Label separator3 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    Composite statusComp = new Composite(shell, SWT.EMBEDDED);

    java.awt.Frame locationFrame = SWT_AWT.new_Frame(locationComp);
    final java.awt.TextField locationText = new java.awt.TextField();
    locationFrame.add(locationText);

    java.awt.Frame fileTableFrame = SWT_AWT.new_Frame(tableComp);
    java.awt.Panel panel = new java.awt.Panel(new java.awt.BorderLayout());
    fileTableFrame.add(panel);
    final JTable fileTable = new JTable(new FileTableModel(null));
    fileTable.setDoubleBuffered(true);
    fileTable.setShowGrid(false);
    fileTable.createDefaultColumnsFromModel();
    JScrollPane scrollPane = new JScrollPane(fileTable);
    panel.add(scrollPane);

    java.awt.Frame statusFrame = SWT_AWT.new_Frame(statusComp);
    statusFrame.setBackground(new java.awt.Color(color.red, color.green, color.blue));
    final java.awt.Label statusLabel = new java.awt.Label();
    statusFrame.add(statusLabel);
    statusLabel.setText("Select a file");

    sash.addListener(SWT.Selection, e -> {
        if (e.detail == SWT.DRAG)
            return;
        GridData data = (GridData) fileTree.getLayoutData();
        Rectangle trim = fileTree.computeTrim(0, 0, 0, 0);
        data.widthHint = e.x - trim.width;
        comp.layout();
    });

    File[] roots = File.listRoots();
    for (int i = 0; i < roots.length; i++) {
        File file = roots[i];
        TreeItem treeItem = new TreeItem(fileTree, SWT.NONE);
        treeItem.setText(file.getAbsolutePath());
        treeItem.setData(file);
        new TreeItem(treeItem, SWT.NONE);
    }
    fileTree.addListener(SWT.Expand, e -> {
        TreeItem item = (TreeItem) e.item;
        if (item == null)
            return;
        if (item.getItemCount() == 1) {
            TreeItem firstItem = item.getItems()[0];
            if (firstItem.getData() != null)
                return;
            firstItem.dispose();
        } else {
            return;
        }
        File root = (File) item.getData();
        File[] files = root.listFiles();
        if (files == null)
            return;
        for (int i = 0; i < files.length; i++) {
            File file = files[i];
            if (file.isDirectory()) {
                TreeItem treeItem = new TreeItem(item, SWT.NONE);
                treeItem.setText(file.getName());
                treeItem.setData(file);
                new TreeItem(treeItem, SWT.NONE);
            }
        }
    });
    fileTree.addListener(SWT.Selection, e -> {
        TreeItem item = (TreeItem) e.item;
        if (item == null)
            return;
        final File root = (File) item.getData();
        EventQueue.invokeLater(() -> {
            statusLabel.setText(root.getAbsolutePath());
            locationText.setText(root.getAbsolutePath());
            fileTable.setModel(new FileTableModel(root.listFiles()));
        });
    });

    GridLayout layout = new GridLayout(4, false);
    layout.marginWidth = layout.marginHeight = 0;
    layout.horizontalSpacing = layout.verticalSpacing = 1;
    shell.setLayout(layout);
    GridData data;
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 4;
    separator1.setLayoutData(data);
    data = new GridData();
    data.horizontalSpan = 1;
    data.horizontalIndent = 10;
    locationLb.setLayoutData(data);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    data.heightHint = locationText.getPreferredSize().height;
    locationComp.setLayoutData(data);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 1;
    toolBar.setLayoutData(data);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 4;
    separator2.setLayoutData(data);
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 4;
    comp.setLayoutData(data);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 4;
    separator3.setLayoutData(data);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 4;
    data.heightHint = statusLabel.getPreferredSize().height;
    statusComp.setLayoutData(data);

    layout = new GridLayout(3, false);
    layout.marginWidth = layout.marginHeight = 0;
    layout.horizontalSpacing = layout.verticalSpacing = 1;
    comp.setLayout(layout);
    data = new GridData(GridData.FILL_VERTICAL);
    data.widthHint = 200;
    fileTree.setLayoutData(data);
    data = new GridData(GridData.FILL_VERTICAL);
    sash.setLayoutData(data);
    data = new GridData(GridData.FILL_BOTH);
    tableComp.setLayoutData(data);

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

From source file:Snippet135.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("SWT and Swing/AWT Example");

    Listener exitListener = new Listener() {
        public void handleEvent(Event e) {
            MessageBox dialog = new MessageBox(shell, SWT.OK | SWT.CANCEL | SWT.ICON_QUESTION);
            dialog.setText("Question");
            dialog.setMessage("Exit?");
            if (e.type == SWT.Close)
                e.doit = false;/*from  w  ww  .j a va  2 s  .  co m*/
            if (dialog.open() != SWT.OK)
                return;
            shell.dispose();
        }
    };
    Listener aboutListener = new Listener() {
        public void handleEvent(Event e) {
            final Shell s = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
            s.setText("About");
            GridLayout layout = new GridLayout(1, false);
            layout.verticalSpacing = 20;
            layout.marginHeight = layout.marginWidth = 10;
            s.setLayout(layout);
            Label label = new Label(s, SWT.NONE);
            label.setText("SWT and AWT Example.");
            Button button = new Button(s, SWT.PUSH);
            button.setText("OK");
            GridData data = new GridData();
            data.horizontalAlignment = GridData.CENTER;
            button.setLayoutData(data);
            button.addListener(SWT.Selection, new Listener() {
                public void handleEvent(Event event) {
                    s.dispose();
                }
            });
            s.pack();
            Rectangle parentBounds = shell.getBounds();
            Rectangle bounds = s.getBounds();
            int x = parentBounds.x + (parentBounds.width - bounds.width) / 2;
            int y = parentBounds.y + (parentBounds.height - bounds.height) / 2;
            s.setLocation(x, y);
            s.open();
            while (!s.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
        }
    };
    shell.addListener(SWT.Close, exitListener);
    Menu mb = new Menu(shell, SWT.BAR);
    MenuItem fileItem = new MenuItem(mb, SWT.CASCADE);
    fileItem.setText("&File");
    Menu fileMenu = new Menu(shell, SWT.DROP_DOWN);
    fileItem.setMenu(fileMenu);
    MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH);
    exitItem.setText("&Exit\tCtrl+X");
    exitItem.setAccelerator(SWT.CONTROL + 'X');
    exitItem.addListener(SWT.Selection, exitListener);
    MenuItem aboutItem = new MenuItem(fileMenu, SWT.PUSH);
    aboutItem.setText("&About\tCtrl+A");
    aboutItem.setAccelerator(SWT.CONTROL + 'A');
    aboutItem.addListener(SWT.Selection, aboutListener);
    shell.setMenuBar(mb);

    RGB color = shell.getBackground().getRGB();
    Label separator1 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    Label locationLb = new Label(shell, SWT.NONE);
    locationLb.setText("Location:");
    Composite locationComp = new Composite(shell, SWT.EMBEDDED);
    ToolBar toolBar = new ToolBar(shell, SWT.FLAT);
    ToolItem exitToolItem = new ToolItem(toolBar, SWT.PUSH);
    exitToolItem.setText("&Exit");
    exitToolItem.addListener(SWT.Selection, exitListener);
    ToolItem aboutToolItem = new ToolItem(toolBar, SWT.PUSH);
    aboutToolItem.setText("&About");
    aboutToolItem.addListener(SWT.Selection, aboutListener);
    Label separator2 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    final Composite comp = new Composite(shell, SWT.NONE);
    final Tree fileTree = new Tree(comp, SWT.SINGLE | SWT.BORDER);
    Sash sash = new Sash(comp, SWT.VERTICAL);
    Composite tableComp = new Composite(comp, SWT.EMBEDDED);
    Label separator3 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    Composite statusComp = new Composite(shell, SWT.EMBEDDED);

    java.awt.Frame locationFrame = SWT_AWT.new_Frame(locationComp);
    final java.awt.TextField locationText = new java.awt.TextField();
    locationFrame.add(locationText);

    java.awt.Frame fileTableFrame = SWT_AWT.new_Frame(tableComp);
    java.awt.Panel panel = new java.awt.Panel(new java.awt.BorderLayout());
    fileTableFrame.add(panel);
    final JTable fileTable = new JTable(new FileTableModel(null));
    fileTable.setDoubleBuffered(true);
    fileTable.setShowGrid(false);
    fileTable.createDefaultColumnsFromModel();
    JScrollPane scrollPane = new JScrollPane(fileTable);
    panel.add(scrollPane);

    java.awt.Frame statusFrame = SWT_AWT.new_Frame(statusComp);
    statusFrame.setBackground(new java.awt.Color(color.red, color.green, color.blue));
    final java.awt.Label statusLabel = new java.awt.Label();
    statusFrame.add(statusLabel);
    statusLabel.setText("Select a file");

    sash.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            if (e.detail == SWT.DRAG)
                return;
            GridData data = (GridData) fileTree.getLayoutData();
            Rectangle trim = fileTree.computeTrim(0, 0, 0, 0);
            data.widthHint = e.x - trim.width;
            comp.layout();
        }
    });

    File[] roots = File.listRoots();
    for (int i = 0; i < roots.length; i++) {
        File file = roots[i];
        TreeItem treeItem = new TreeItem(fileTree, SWT.NONE);
        treeItem.setText(file.getAbsolutePath());
        treeItem.setData(file);
        new TreeItem(treeItem, SWT.NONE);
    }
    fileTree.addListener(SWT.Expand, new Listener() {
        public void handleEvent(Event e) {
            TreeItem item = (TreeItem) e.item;
            if (item == null)
                return;
            if (item.getItemCount() == 1) {
                TreeItem firstItem = item.getItems()[0];
                if (firstItem.getData() != null)
                    return;
                firstItem.dispose();
            } else {
                return;
            }
            File root = (File) item.getData();
            File[] files = root.listFiles();
            if (files == null)
                return;
            for (int i = 0; i < files.length; i++) {
                File file = files[i];
                if (file.isDirectory()) {
                    TreeItem treeItem = new TreeItem(item, SWT.NONE);
                    treeItem.setText(file.getName());
                    treeItem.setData(file);
                    new TreeItem(treeItem, SWT.NONE);
                }
            }
        }
    });
    fileTree.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            TreeItem item = (TreeItem) e.item;
            if (item == null)
                return;
            final File root = (File) item.getData();
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    statusLabel.setText(root.getAbsolutePath());
                    locationText.setText(root.getAbsolutePath());
                    fileTable.setModel(new FileTableModel(root.listFiles()));
                }
            });
        }
    });

    GridLayout layout = new GridLayout(4, false);
    layout.marginWidth = layout.marginHeight = 0;
    layout.horizontalSpacing = layout.verticalSpacing = 1;
    shell.setLayout(layout);
    GridData data;
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 4;
    separator1.setLayoutData(data);
    data = new GridData();
    data.horizontalSpan = 1;
    data.horizontalIndent = 10;
    locationLb.setLayoutData(data);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    data.heightHint = locationText.getPreferredSize().height;
    locationComp.setLayoutData(data);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 1;
    toolBar.setLayoutData(data);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 4;
    separator2.setLayoutData(data);
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 4;
    comp.setLayoutData(data);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 4;
    separator3.setLayoutData(data);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 4;
    data.heightHint = statusLabel.getPreferredSize().height;
    statusComp.setLayoutData(data);

    layout = new GridLayout(3, false);
    layout.marginWidth = layout.marginHeight = 0;
    layout.horizontalSpacing = layout.verticalSpacing = 1;
    comp.setLayout(layout);
    data = new GridData(GridData.FILL_VERTICAL);
    data.widthHint = 200;
    fileTree.setLayoutData(data);
    data = new GridData(GridData.FILL_VERTICAL);
    sash.setLayoutData(data);
    data = new GridData(GridData.FILL_BOTH);
    tableComp.setLayoutData(data);

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

From source file:RadialLayout.java

/**
 * Run a demonstration./*from w  w  w. j ava  2  s  .c  o m*/
 *
 * @param args  ignored.
 * 
 * @throws Exception when an error occurs.
 */
public static void main(final String[] args) throws Exception {
    final Frame frame = new Frame();
    final Panel panel = new Panel();
    panel.setLayout(new RadialLayout());

    panel.add(new Checkbox("One"));
    panel.add(new Checkbox("Two"));
    panel.add(new Checkbox("Three"));
    panel.add(new Checkbox("Four"));
    panel.add(new Checkbox("Five"));
    panel.add(new Checkbox("One"));
    panel.add(new Checkbox("Two"));
    panel.add(new Checkbox("Three"));
    panel.add(new Checkbox("Four"));
    panel.add(new Checkbox("Five"));

    frame.add(panel);
    frame.setSize(300, 500);
    frame.setVisible(true);
}

From source file:org.eclipse.swt.snippets.Snippet361.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 361");
    shell.setText("Translate and Rotate an AWT Image in an SWT GUI");
    shell.setLayout(new GridLayout(8, false));

    Button fileButton = new Button(shell, SWT.PUSH);
    fileButton.setText("&Open Image File");
    fileButton.addSelectionListener(widgetSelectedAdapter(e -> {
        String filename = new FileDialog(shell).open();
        if (filename != null) {
            image = Toolkit.getDefaultToolkit().getImage(filename);
            canvas.repaint();// w  ww  . ja  va2  s.  c  om
        }
    }));

    new Label(shell, SWT.NONE).setText("Translate &X by:");
    final Combo translateXCombo = new Combo(shell, SWT.NONE);
    translateXCombo.setItems("0", "image width", "image height", "100", "200");
    translateXCombo.select(0);
    translateXCombo.addModifyListener(e -> {
        translateX = numericValue(translateXCombo);
        canvas.repaint();
    });

    new Label(shell, SWT.NONE).setText("Translate &Y by:");
    final Combo translateYCombo = new Combo(shell, SWT.NONE);
    translateYCombo.setItems("0", "image width", "image height", "100", "200");
    translateYCombo.select(0);
    translateYCombo.addModifyListener(e -> {
        translateY = numericValue(translateYCombo);
        canvas.repaint();
    });

    new Label(shell, SWT.NONE).setText("&Rotate by:");
    final Combo rotateCombo = new Combo(shell, SWT.NONE);
    rotateCombo.setItems("0", "Pi", "Pi/2", "Pi/4", "Pi/8");
    rotateCombo.select(0);
    rotateCombo.addModifyListener(e -> {
        rotate = numericValue(rotateCombo);
        canvas.repaint();
    });

    Button printButton = new Button(shell, SWT.PUSH);
    printButton.setText("&Print Image");
    printButton.addSelectionListener(widgetSelectedAdapter(e -> {
        performPrintAction(display, shell);
    }));

    composite = new Composite(shell, SWT.EMBEDDED | SWT.BORDER);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 8, 1);
    data.widthHint = 640;
    data.heightHint = 480;
    composite.setLayoutData(data);
    Frame frame = SWT_AWT.new_Frame(composite);
    canvas = new Canvas() {
        @Override
        public void paint(Graphics g) {
            if (image != null) {
                g.setColor(Color.WHITE);
                g.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());

                /* Use Java2D here to modify the image as desired. */
                Graphics2D g2d = (Graphics2D) g;
                AffineTransform t = new AffineTransform();
                t.translate(translateX, translateY);
                t.rotate(rotate);
                g2d.setTransform(t);
                /*------------*/

                g.drawImage(image, 0, 0, this);
            }
        }
    };
    frame.add(canvas);
    composite.getAccessible().addAccessibleListener(new AccessibleAdapter() {
        @Override
        public void getName(AccessibleEvent e) {
            e.result = "Image drawn in AWT Canvas";
        }
    });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.talend.dataprofiler.chart.util.ChartUtils.java

/**
 * Create a AWT_SWT bridge composite for displaying the <CODE>ChartPanel</CODE>.
 * /*from   w  w  w. j  a v  a 2s  .  c  om*/
 * @param composite
 * @param gd
 * @param chartPanel
 */
public static ChartPanel createAWTSWTComp(Composite composite, GridData gd, JFreeChart chart) {

    ChartPanel chartPanel = new ChartPanel(chart);
    Composite frameComp = new Composite(composite, SWT.EMBEDDED);
    frameComp.setLayout(new GridLayout());
    frameComp.setLayoutData(gd);
    frameComp.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));

    Frame frame = SWT_AWT.new_Frame(frameComp);
    frame.setLayout(new java.awt.GridLayout());
    frame.add(chartPanel);
    frame.validate();

    return chartPanel;
}

From source file:org.qsos.radar.GenerateRadar.java

/**
 * This class creates a composite in which the radar char will be
 * implemented/*  w w w  .j  a v  a  2  s  .  co  m*/
 * 
 * @param parent
 *             Composite where the chart will be seen
 * @param Categories
 *             String[] that contains the name of the elements [4 min and 7 max] the user has chosen to visualize
 * @param Scores
 *             Double[] that contains the average score of each category
 * @return Control
 * 
 */
public static Control createChart(Composite parent, String[] Categories, double[] Scores) {

    Composite Charcomposite = new Composite(parent, SWT.EMBEDDED);
    Charcomposite.setLayout(new FillLayout());
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    //
    for (int i = 0; i < CatNumber; i++) {
        dataset.addValue(Scores[i], getTitle(), Categories[i]);
    }

    String BackGroundMire = null;

    //Configuration of the spiderwebplot
    SpiderWebPlot plot = new SpiderWebPlot();
    plot.setDataset(dataset);
    plot.setMaxValue(JQConst.RADAR_MAX_VALUE);
    plot.setSeriesPaint(JQConst.RADAR_SERIES_PAINT);
    plot.setAxisLabelGap(JQConst.RADAR_AXIS_LABEL_GAP);
    plot.setHeadPercent(JQConst.RADAR_HEAD_PERCENT);
    plot.setInteriorGap(JQConst.RADAR_INTERIOR_GAP);
    plot.setWebFilled(true);

    //The backgroundpicture used as a spiderweb is chosen according to the 
    //number of categories selected
    switch (CatNumber) {
    case 4:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_4;
        break;
    case 5:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_5;
        break;
    case 6:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_6;
        break;
    case 7:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_7;
        break;
    }
    javax.swing.ImageIcon icon = new javax.swing.ImageIcon(BackGroundMire);
    plot.setBackgroundImage(icon.getImage());

    //chart creation
    JFreeChart chart = new JFreeChart(plot);

    //Here the background color from the shell is taken in order to match AWT and SWT backgrounds
    Color backgroundColor = parent.getBackground();

    //JFreechart doesn't support SWT so we create an AWT Frame that will depend on Charcomposite
    java.awt.Frame chartPanel = SWT_AWT.new_Frame(Charcomposite);
    chartPanel.setLayout(new java.awt.GridLayout());
    ChartPanel jfreeChartPanel = new ChartPanel(chart);

    chartPanel.setBackground(new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(),
            backgroundColor.getBlue()));

    chartPanel.add(jfreeChartPanel);
    chartPanel.pack();

    return parent;

}

From source file:grafici.PazientiPieChart.java

/**
 * Default constructor./* w  w w  .  j  a v  a  2  s. com*/
 * 
 * @param title
 *            the frame title.
 */
public PazientiPieChart(String title, Composite parent, int style, int tipo) {
    super(parent, style);
    titolo = title;
    Composite cmp = new Composite(this, SWT.FILL | SWT.EMBEDDED);
    GridData gdCmp = new GridData(SWT.FILL);
    gdCmp.horizontalAlignment = SWT.FILL;
    gdCmp.verticalAlignment = SWT.FILL;
    gdCmp.grabExcessHorizontalSpace = true;
    gdCmp.grabExcessVerticalSpace = true;
    cmp.setLayoutData(gdCmp);
    cmp.setLayout(new GridLayout(1, false));

    JPanel chartPanel = createDemoPanel(tipo);
    Frame graphFrame = SWT_AWT.new_Frame(cmp);
    graphFrame.add(chartPanel);
    graphFrame.pack();

    GridData gdThis = new GridData(SWT.FILL);
    gdThis.horizontalAlignment = SWT.FILL;
    gdThis.verticalAlignment = SWT.FILL;
    gdThis.grabExcessHorizontalSpace = true;
    gdThis.grabExcessVerticalSpace = true;

    this.setLayoutData(gdThis);
    this.setLayout(new GridLayout(1, false));
}