List of usage examples for org.eclipse.swt.widgets Label getBounds
public Rectangle getBounds()
From source file:org.eclipse.swt.snippets.Snippet335.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 335"); shell.setLayout(new GridLayout()); Label label = new Label(shell, SWT.WRAP | SWT.BORDER); GridData labelData = new GridData(); labelData.widthHint = 10; /* default width */ labelData.horizontalAlignment = SWT.FILL; /* grow to fill available width */ label.setLayoutData(labelData);/*from www. j a va2 s . com*/ label.setText( "Snippets are minimal stand-alone programs that demonstrate specific techniques or functionality."); new Button(shell, SWT.PUSH).setText("This button determines the Shell's width"); /* do an initial pack() so that the Shell determines its required width */ shell.pack(); /* update the Label's width hint to match what the layout allocated for it */ labelData.widthHint = label.getBounds().width; /* * do a second pack() so that the Label will compute its required height * based on its correct width instead of its previously-set default width */ shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }