Layoutmanager-Problem: Label to big to show correctly [message #441022] |
Tue, 10 August 2004 07:36 |
Eclipse User |
|
|
|
Originally posted by: IngolfBayer.gmx.de
Hi,
i am new to java and have a simple Form with two groups (One group left, the
second group right of it). In the second group i will display a Label-Widget
with wordbreaking. The Label is often to width to display. Why ?
Thanks!
Ingolf
Here is the source-code:
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.*;
public class TestLayout {
private Display display;
private Shell shell;
TestLayout() {
display = new Display();
shell = new Shell(display);
shell.setText("Test Layoutmanager");
createGUI();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private void createGUI() {
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
gridLayout.marginHeight = 10;
gridLayout.marginWidth = 10;
shell.setLayout(gridLayout);
GridData datashell = new GridData (GridData.GRAB_HORIZONTAL |
GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_VERTICAL |
GridData.VERTICAL_ALIGN_FILL);
shell.setLayoutData(datashell);
/* Create a group for the tree */
Group treeGroup = new Group (shell, SWT.NONE);
treeGroup.setLayout (new FillLayout (SWT.HORIZONTAL));
GridData gd1 = new GridData (GridData.GRAB_HORIZONTAL |
GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_VERTICAL |
GridData.VERTICAL_ALIGN_FILL);
gd1.widthHint = 200;
treeGroup.setLayoutData (gd1);
treeGroup.setText ("Group 1");
/* Create a group for the text */
Group textGroup = new Group (shell, SWT.NONE);
textGroup.setLayout (new FillLayout (SWT.HORIZONTAL));
textGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL |
GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_VERTICAL |
GridData.VERTICAL_ALIGN_FILL));
textGroup.setText ("Group 2");
Label aLabel = new Label (textGroup, SWT.READ_ONLY | SWT.SIMPLE |
SWT.V_SCROLL);
StringBuffer p = new StringBuffer("");
p.append("This is a very little Text to test the Layout-Manager. The
wordbreak doesn't work correct");
p.append(" when the label is in the right group. Without a group it
seems ok!");
p.append(" I think the problem is that the label is to width when the
window-width is to small!");
aLabel.setText(p.toString());
}
public static void main(String[] args) {
new TestLayout();
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03631 seconds