Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » text areas
text areas [message #467047] Mon, 23 January 2006 19:08 Go to next message
Eclipse UserFriend
Originally posted by: mikko.tanskanen.tut.fi

Hi, I have a question. When I have a layout with a textarea on top an
another one
on the bottom with a button, I don't seem to be able to get a newline to
work.
That \n-character in area.append only shows as two rectangles within the
text.

Also, if text is longer that the width of the text area, how can I make it
to
continue the text on the new line? Without parsing the String. Is there a
good and easy way to do this?

Here's the main part of the code:

FillLayout fl = new FillLayout();
fl.type = SWT.VERTICAL;

SashForm wholePane = new SashForm(shell_, SWT.VERTICAL);
wholePane.setBackground(whiteColor_);

SashForm textSash = new SashForm(wholePane, SWT.VERTICAL);
textSash.setBackground(whiteColor_);

SashForm inputSash = new SashForm(wholePane, SWT.HORIZONTAL);
inputSash.setBackground(whiteColor_);

wholePane.setWeights(new int[]{7,1});

Text area = new Text(textSash, SWT.SINGLE | SWT.VERTICAL );
area.setEditable(false);
area.setBackground(whiteColor_);
area.append("1234567890 \n 1234567890");

final Text input = new Text(inputSash, SWT.SINGLE | SWT.BORDER);
input.setBackground(whiteColor_);

Button send = new Button(inputSash, SWT.PUSH);
send.setText("send");


Thanks in advance.

-Mikko

--
"
Re: text areas [message #467061 is a reply to message #467047] Mon, 23 January 2006 19:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mikko.tanskanen.tut.fi

Also, I would like to get a scrollbar in the text area on top.

And what's the keycode for enter key? I haven't found that anywhere.

--
"
Re: text areas [message #467081 is a reply to message #467047] Tue, 24 January 2006 15:36 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
You have created your Text widget with the style SWT.SINGLE - this means the
text widget can only have one line and \n will be treated as an invalid
character. Create your Text widget with the style SWT.MULTI to have
multiple lines.

To make the text wrap around to a new line when the text widget is not wide
enough to show the whole string, create Text with the style SWT.WRAP.

To get a scrollbar you need to create the Text widget with the style
SWT.V_SCROLL or SWT.H_SCROLL.

I think what you want is :

Text area = new Text(textSash, SWT.MULTI| SWT.WRAP | SWT.V_SCROLL);


"Mikko Tanskanen" <mikko.tanskanen@tut.fi> wrote in message
news:dr39kh$bgp$1@utils.eclipse.org...
> Hi, I have a question. When I have a layout with a textarea on top an
> another one
> on the bottom with a button, I don't seem to be able to get a newline to
> work.
> That \n-character in area.append only shows as two rectangles within the
> text.
>
> Also, if text is longer that the width of the text area, how can I make it
> to
> continue the text on the new line? Without parsing the String. Is there a
> good and easy way to do this?
>
> Here's the main part of the code:
>
> FillLayout fl = new FillLayout();
> fl.type = SWT.VERTICAL;
>
> SashForm wholePane = new SashForm(shell_, SWT.VERTICAL);
> wholePane.setBackground(whiteColor_);
>
> SashForm textSash = new SashForm(wholePane, SWT.VERTICAL);
> textSash.setBackground(whiteColor_);
>
> SashForm inputSash = new SashForm(wholePane, SWT.HORIZONTAL);
> inputSash.setBackground(whiteColor_);
>
> wholePane.setWeights(new int[]{7,1});
>
> Text area = new Text(textSash, SWT.SINGLE | SWT.VERTICAL );
> area.setEditable(false);
> area.setBackground(whiteColor_);
> area.append("1234567890 \n 1234567890");
>
> final Text input = new Text(inputSash, SWT.SINGLE | SWT.BORDER);
> input.setBackground(whiteColor_);
>
> Button send = new Button(inputSash, SWT.PUSH);
> send.setText("send");
>
>
> Thanks in advance.
>
> -Mikko
>
> --
> "
Re: text areas [message #467082 is a reply to message #467061] Tue, 24 January 2006 15:37 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
What do you want to do on Enter? Is this in a single line text widget or a
multi line text widget?

"Mikko Tanskanen" <mikko.tanskanen@tut.fi> wrote in message
news:dr3cjr$j4i$1@utils.eclipse.org...
> Also, I would like to get a scrollbar in the text area on top.
>
> And what's the keycode for enter key? I haven't found that anywhere.
>
> --
> "
Re: text areas [message #467085 is a reply to message #467081] Tue, 24 January 2006 15:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mikko.tanskanen.tut.fi

"Veronika Irvine" <veronika_irvine@oti.com> wrote in message
news:dr5hhs$857$1@utils.eclipse.org...
> You have created your Text widget with the style SWT.SINGLE - this means
the
> text widget can only have one line and \n will be treated as an invalid
> character. Create your Text widget with the style SWT.MULTI to have
> multiple lines.
>
> To make the text wrap around to a new line when the text widget is not
wide
> enough to show the whole string, create Text with the style SWT.WRAP.
>
> To get a scrollbar you need to create the Text widget with the style
> SWT.V_SCROLL or SWT.H_SCROLL.
>
> I think what you want is :
>
> Text area = new Text(textSash, SWT.MULTI| SWT.WRAP | SWT.V_SCROLL);

Thank you, that did the job.

-Mikko
Re: text areas [message #467086 is a reply to message #467082] Tue, 24 January 2006 15:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mikko.tanskanen.tut.fi

"Veronika Irvine" <veronika_irvine@oti.com> wrote in message
news:dr5hjg$8bd$1@utils.eclipse.org...
> What do you want to do on Enter? Is this in a single line text widget or
a
> multi line text widget?
>


Single line text widget. I have to send the written text forward when I have
typed in something and pressed enter.

--
"
Re: text areas [message #467148 is a reply to message #467086] Wed, 25 January 2006 18:54 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
For a single line text widget you need to add a Traverse listener:

public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new GridLayout(3, false));
Button b = new Button(shell, SWT.PUSH);
b.setText("Button 1");
b.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
System.out.println(e.widget+" selected");
}
});
Text text = new Text(shell, SWT.SINGLE);
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
text.addListener(SWT.Traverse, new Listener() {
public void handleEvent(Event e) {
if (e.detail == SWT.TRAVERSE_RETURN) {
System.out.println("do something on
return");
}
}
});
b = new Button(shell, SWT.PUSH);
b.setText("Button2");
b.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
System.out.println(e.widget+" selected");
}
});
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}


"Mikko Tanskanen" <mikko.tanskanen@tut.fi> wrote in message
news:dr5ish$b8d$1@utils.eclipse.org...
> "Veronika Irvine" <veronika_irvine@oti.com> wrote in message
> news:dr5hjg$8bd$1@utils.eclipse.org...
>> What do you want to do on Enter? Is this in a single line text widget or
> a
>> multi line text widget?
>>
>
>
> Single line text widget. I have to send the written text forward when I
> have
> typed in something and pressed enter.
>
> --
> "
Re: text areas [message #467155 is a reply to message #467148] Wed, 25 January 2006 20:44 Go to previous message
Eclipse UserFriend
Originally posted by: mikko.tanskanen.tut.fi

Thank you.

--
"
Previous Topic:TableViewer CheckCellEditor
Next Topic:DirectoryDialog question
Goto Forum:
  


Current Time: Mon Sep 23 15:13:25 GMT 2019

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

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

Back to the top