Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT Multiline text resizing and wrapping
SWT Multiline text resizing and wrapping [message #511216] Sun, 31 January 2010 11:27 Go to next message
Simon L. is currently offline Simon L.
Messages: 22
Registered: January 2010
Junior Member
Hello,
simple question I think, but can't find an answer:

(GridLayout)
I have a container with multiple controls grabbing horizontal space and filling it. And a multiline text, which I want to fill the container horizontally, too, but with not being responsible for the width the container has.
it means, that I want the multiline text to have always the width of the container, but I dont want a long string in the text field to make the container take more horizontal space than it would take without the text field.

Thanks in advance Smile
Re: SWT Multiline text resizing and wrapping [message #511229 is a reply to message #511216] Sun, 31 January 2010 15:15 Go to previous messageGo to next message
steven is currently offline steven
Messages: 7
Registered: August 2009
Location: China
Junior Member

I think this code can help you:
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());
		shell.setSize(400, 400);
		Composite compos = new Composite(shell, SWT.NONE);
		compos.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
		GridLayout layout = new GridLayout();
		compos.setLayout(layout);
		final Label label = new Label(compos, SWT.WRAP);
		final GridData data = new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1);
		label.setLayoutData(data);
		label.setText("asda sda sdasd asda sda sdada dadads asd adsad as dadsa sad sada dsasda sd adsa sasd");
		label.setBackground(display.getSystemColor(SWT.COLOR_RED));
		new Button(compos, SWT.PUSH).setText("sfdsfsd");
		
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();

Re: SWT Multiline text resizing and wrapping [message #511257 is a reply to message #511229] Sun, 31 January 2010 23:12 Go to previous messageGo to next message
Simon L. is currently offline Simon L.
Messages: 22
Registered: January 2010
Junior Member
Hi,
doesn't work for me. You can set the site for your Shell hard, what I can't do with my container.. I tried all combination of grabHorizontalSpace and fill / left in the general horizontal direction. That didn't do nothing.
I get:
http://content.screencast.com/users/simlei/folders/Jing/media/ad2d01ce-d99c-4bea-a7df-4a98b86aeec6/2010-02-01_0009.png
but I don#t want the text to be longer than the button, but multilined instead....

I have the following code:

composite3 = new Composite(this, SWT.NONE);
				GridLayout composite3Layout = new GridLayout();
				composite3Layout.makeColumnsEqualWidth = true;
				GridData composite3LData = new GridData();
				composite3LData.grabExcessVerticalSpace = true;
				composite3LData.verticalAlignment = GridData.FILL;
				composite3.setLayoutData(composite3LData);
				composite3.setLayout(composite3Layout);
				{
					button2 = new Button(composite3, SWT.PUSH | SWT.CENTER);
					GridData button2LData = new GridData();
					button2LData.widthHint = 161;
					button2LData.heightHint = 25;
					button2.setLayoutData(button2LData);
					button2.setText("button2");
				}
				{
					text1 = new Text(composite3, SWT.MULTI | SWT.WRAP | SWT.TRANSPARENT);
					GridData text1LData = new GridData();
					text1LData.horizontalAlignment = GridData.FILL;
					text1LData.grabExcessHorizontalSpace = true;
					//text1LData.widthHint = 60;
					text1.setLayoutData(text1LData);
					text1.setText("Find the right blocklength and try to move the columns to find the plaintext.");
					text1.setEditable(false);
				}
Re: SWT Multiline text resizing and wrapping [message #511282 is a reply to message #511257] Mon, 01 February 2010 05:16 Go to previous messageGo to next message
steven is currently offline steven
Messages: 7
Registered: August 2009
Location: China
Junior Member

Hi, As I can't see the full scene of you code(I mean those parent composites). So I just assume the parent container is Shell.
And somewhat,I do think there is a bug or bad implement of swt Label control.

So those code just for your reference.

try this code:

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class TestMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		Display display = new Display();

	    Shell shell = new Shell(display);
	    shell.setSize(400, 400);

		Button button2;
		Text text1;
		
		Composite composite3 = new Composite(shell, SWT.NONE);
		GridLayout composite3Layout = new GridLayout();
		composite3.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
		composite3.setLayout(composite3Layout);
		composite3Layout.makeColumnsEqualWidth = true;
		
		button2 = new Button(composite3, SWT.PUSH | SWT.CENTER);
		GridData button2LData = new GridData();
		button2LData.widthHint = 161;
		button2LData.heightHint = 25;
		button2.setLayoutData(button2LData);
		button2.setText("button2");
		
		text1 = new Text(composite3, SWT.MULTI | SWT.WRAP | SWT.TRANSPARENT);
		GridData text1LData = new GridData();
		text1LData.horizontalAlignment = GridData.FILL;
		text1LData.grabExcessHorizontalSpace = true;
		text1LData.widthHint = 161;
		text1.setLayoutData(text1LData);
		text1.setText("Find the right blocklength and try to move the columns to find the plaintext.");
		text1.setEditable(false);
		composite3.pack();

	    shell.open();
	    while (!shell.isDisposed()) {
	        if (!display.readAndDispatch()) display.sleep();
	    }
	    display.dispose();
	}
}
Re: SWT Multiline text resizing and wrapping [message #511455 is a reply to message #511216] Mon, 01 February 2010 11:10 Go to previous messageGo to next message
Grant Gayed is currently offline Grant Gayed
Messages: 2151
Registered: July 2009
Senior Member
I think this shows what you want:

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Composite compos = new Composite(shell, SWT.NONE);
GridLayout layout = new GridLayout();
compos.setLayout(layout);
final Label label = new Label(compos, SWT.WRAP);
GridData data = new GridData();
data.widthHint = 10; // <-- minimum width, will grow based on Button
width
data.horizontalAlignment = SWT.FILL;
label.setLayoutData(data);
label.setText("asda sda sdasd asda sda sdada dadads asd adsad as dadsa
sad sada dsasda sd adsa sasd");
new Button(compos, SWT.PUSH).setText("sfdsfsd sfdsfsd sfdsfsd sfdsfsd
sfdsfsd sfdsfsd");
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

Grant


"Simon L." <abcba1307@yahoo.de> wrote in message
news:hk3pem$h42$1@build.eclipse.org...
> Hello,
> simple question I think, but can't find an answer:
>
> (GridLayout)
> I have a container with multiple controls grabbing horizontal space and
filling it. And a multiline text, which I want to fill the container
horizontally, too, but with not being responsible for the width the
container has.
> it means, that I want the multiline text to have always the width of the
container, but I dont want a long string in the text field to make the
container take more horizontal space than it would take without the text
field.
>
> Thanks in advance :)
Re: SWT Multiline text resizing and wrapping [message #511485 is a reply to message #511455] Mon, 01 February 2010 17:15 Go to previous messageGo to next message
Simon L. is currently offline Simon L.
Messages: 22
Registered: January 2010
Junior Member
Thanks, that was the answer.. setting a small widthHint!

I'm happy Smile
Re: SWT Multiline text resizing and wrapping [message #511972 is a reply to message #511485] Wed, 03 February 2010 15:02 Go to previous message
Grant Gayed is currently offline Grant Gayed
Messages: 2151
Registered: July 2009
Senior Member
I've posted a snippet with this solution at
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet335.java?view=co ,
but note that it contains an additional wrinkle that the previous snippet in
this thread didn't. A bad side effect of setting the small widthHint is
that the Label initially thinks it has to be very tall to show its content,
and as a result it can cause its parent to be unnecessarily tall. The
linked snippet does its pack() in two stages to allow the parent's height to
be correctly set.

Grant


"Simon L." <abcba1307@yahoo.de> wrote in message
news:hk727g$tr$1@build.eclipse.org...
> Thanks, that was the answer.. setting a small widthHint!
>
> I'm happy :)
Previous Topic:Save view as jpg image
Next Topic:jface alternating row background color
Goto Forum:
  


Current Time: Sun Oct 26 06:13:29 GMT 2014

Powered by FUDForum. Page generated in 0.01979 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software