Eclipse插件开发:SWT布局之FillLayout 有更新!

    FillLayout即填充布局,布局后的控件,完全填充其父控件。


    import org.eclipse.swt.SWT;
    import org.eclipse.swt.events.SelectionAdapter;
    import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.layout.FillLayout;
    import org.eclipse.swt.widgets.Button;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Shell;
    
    public class FillLayoutExample {
    	public static void main(String[] args) {
    		Button button;
    		Display display = new Display();
    		Shell shell = new Shell(display);
    		shell.setText("FillLayout Example");
    		shell.setBounds(100, 100, 400, 75);
    		shell.setLayout(new FillLayout());
    		for (int i = 1; i <= 8; i++) {
    			button = new Button(shell, SWT.PUSH);
    			button.setText("B" + i);
    			button.addSelectionListener(new SelectionAdapter() {
    				public void widgetSelected(SelectionEvent event) {
    					System.out.println(((Button) event.widget).getText()
    							+ " was clicked!");
    				}
    			});
    		}
    		shell.open();
    		while (!shell.isDisposed()) {
    			if (!display.readAndDispatch())
    				display.sleep();
    		}
    		display.dispose();
    	}
    }
    控件的大小随窗口的变化而变大变小,总是填充父窗口:



    本文为风林火山博客原创,转载请注明出处:www.flcoder.com
    validate