www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.dwt - dwt ScrolledComposite snippet

import dwt.DWT;
import dwt.layout.FillLayout;
import dwt.layout.GridData;
import dwt.layout.GridLayout;
import dwt.widgets.Button;
import dwt.widgets.Composite;
import dwt.widgets.Display;
import dwt.widgets.Shell;
import dwt.widgets.Group;
import dwt.widgets.TabFolder;
import dwt.widgets.TabItem;
import dwt.custom.ScrolledComposite;
import dwt.events.ControlAdapter;
import dwt.events.ControlEvent;
import dwt.graphics.Point;

import dwt.dwthelper.utils;

import tango.util.Convert;

/**
 *  author qingkangxu
 * 
 * Port to the D programming language:
 *     yidabu at gmail dot com  ( D China
http://www.d-programming-language-china.org/ )
 *     ( D programming language Chinese Forum
http://bbs.d-programming-language-china.org/ )
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */


    void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display, DWT.SHELL_TRIM);
        shell.setText("TabFolder");
        shell.setLayout(new FillLayout());

        TabFolder folder = new TabFolder(shell, DWT.NONE);
        TabItem item1 = new TabItem(folder, DWT.NONE);
        item1.setText("label");
        
        // create the sc
        final ScrolledComposite sc = new ScrolledComposite(folder,
DWT.V_SCROLL);
        sc.setExpandHorizontal(true);
        sc.setExpandVertical(true);
        sc.getVerticalBar().setIncrement(5);

        // create the composite on the sc
        final Composite endpointComp = new Composite(sc, DWT.NONE);
        GridData suGridData = new GridData(GridData.FILL_BOTH);
        endpointComp.setLayoutData(suGridData);
        endpointComp.setLayout(new GridLayout(1, true));
        //add button to the endpointComp
        addCompToEndpointComp(endpointComp);

        sc.addControlListener(new class ControlAdapter {
            public void controlResized(ControlEvent e) {

                Point p = endpointComp.computeSize(DWT.DEFAULT, DWT.DEFAULT);
                sc.setMinSize(p.x, p.y + 10);
                endpointComp.layout();
            }
        });
        sc.setContent(endpointComp);        
        item1.setControl(sc);

        TabItem item2 = new TabItem(folder, DWT.NONE);
        item2.setText("radio");
        Group group2 = new Group(folder, DWT.NONE);
        group2.setText("Radio Group");
        group2.setLayout(new GridLayout());
        Button radio1 = new Button(group2, DWT.RADIO);
        radio1.setText("radio1");
        Button radio2 = new Button(group2, DWT.RADIO);
        radio2.setText("radio2");
        item2.setControl(group2);

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

    void addCompToEndpointComp(Composite endpointComp) {
        for (int i = 0; i < 20; i++) {
            Button button = new Button(endpointComp, DWT.PUSH);
            button.setText("ForTestBtn"  ~ to!(String)(i));
            button.setLayoutData(new GridData());
        }

    }


-- 
yidabu <yidabu.spam gmail.com>
http://www.dsource.org/projects/dwin

D -(D Chinese):
http://www.d-programming-language-china.org/
http://bbs.d-programming-language-china.org/
http://dwin.d-programming-language-china.org/
http://scite4d.d-programming-language-china.org/
Nov 02 2008