Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Multi line label
Multi line label [message #443631] Tue, 28 September 2004 21:02 Go to next message
No real name is currently offline No real nameFriend
Messages: 21
Registered: July 2009
Junior Member
Hello,

I have to show some name value pairs in a dialog.
The dialog has a fixed size (PPC).
I used GridLayout with two columns.
The scheme is as folowing:
date label (1. column) | concrete date (2. column)
descr label | description text
An example:
....
date: 09.25.04
description: Now a longer description which
contains many words.

date: 09.28.04
description: Now a longer description which
contains many words.
....

The problem is the label with the description, which needs
often more than one row. I need a multi line label but SWT
declared SWT.MULTI not for labels.
Thats why, I tried a text field with text.setEnabled(false);
for showing the description. But that causes two problems:

1. I have to set the height of the description text field so
that the height is sufficient but not bigger.
GridData.FILL_VERTICAL lets free space and gridData.heighHint
demands the optimal height of the label which I don't know.
I tried also with pack() but had no success.

2. The font looks disabled and because I set
setEnabled(false) setForeGround(black) and so on has no
effect.

That seems to be a simple problem but I searched a solution
for a long time without result. Does anybody know how I
can display multi line labels?

Regards, Tobi

************************************************************ ****

text = new Text(shell, SWT.MULTI | SWT.WRAP);
text.setEnabled(false);
text.setText(buffer.toString());
gridData = new GridData(GridData.FILL_HORIZONTAL
| GridData.FILL_VERTICAL);
text.setLayoutData(gridData);
Re: Multi line label [message #443633 is a reply to message #443631] Tue, 28 September 2004 21:35 Go to previous messageGo to next message
Benjamin Pasero is currently offline Benjamin PaseroFriend
Messages: 337
Registered: July 2009
Senior Member
Hi Tobi,
as a quick solution regarding your second problem, try calling
Text with "SWT.READ_ONLY". That allows the Text widget to be
readonly, but does not show the Text grayed out (as with using
setEnabled(false)).
Ben


> Hello,

> I have to show some name value pairs in a dialog.
> The dialog has a fixed size (PPC).
> I used GridLayout with two columns.
> The scheme is as folowing:
> date label (1. column) | concrete date (2. column)
> descr label | description text
> An example:
> ....
> date: 09.25.04
> description: Now a longer description which
> contains many words.

> date: 09.28.04
> description: Now a longer description which
> contains many words.
> ....

> The problem is the label with the description, which needs
> often more than one row. I need a multi line label but SWT
> declared SWT.MULTI not for labels.
> Thats why, I tried a text field with text.setEnabled(false);
> for showing the description. But that causes two problems:

> 1. I have to set the height of the description text field so
> that the height is sufficient but not bigger.
> GridData.FILL_VERTICAL lets free space and gridData.heighHint
> demands the optimal height of the label which I don't know.
> I tried also with pack() but had no success.

> 2. The font looks disabled and because I set
> setEnabled(false) setForeGround(black) and so on has no
> effect.

> That seems to be a simple problem but I searched a solution
> for a long time without result. Does anybody know how I
> can display multi line labels?

> Regards, Tobi

> ************************************************************ ****

> text = new Text(shell, SWT.MULTI | SWT.WRAP);
> text.setEnabled(false);
> text.setText(buffer.toString());
> gridData = new GridData(GridData.FILL_HORIZONTAL
> | GridData.FILL_VERTICAL);
> text.setLayoutData(gridData);
Re: Multi line label [message #443638 is a reply to message #443633] Wed, 29 September 2004 06:57 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 21
Registered: July 2009
Junior Member
> as a quick solution regarding your second problem, try calling
> Text with "SWT.READ_ONLY". That allows the Text widget to be
> readonly, but does not show the Text grayed out (as with using
> setEnabled(false)).
Thank you, but this helps not really (cursor visible and background).
And there is still the ugly other problem with the space.

Regards, Tobi
Re: Multi line label [message #443689 is a reply to message #443631] Wed, 29 September 2004 09:58 Go to previous messageGo to next message
Richard Moore is currently offline Richard MooreFriend
Messages: 71
Registered: July 2009
Member
Hi Tobi,

Try using a text and setting the editable to false, you could even change
the background color to gray... looks like a label then... I think setting
enable to false stops the scrolling of a text ? editable I do not know if
the scrolling still works... try it out.

Regards
Richard


"Tobi Wink" <tobi.winkesf@lycos.com> wrote in message
news:cjck1d$uh1$1@eclipse.org...
> Hello,
>
> I have to show some name value pairs in a dialog.
> The dialog has a fixed size (PPC).
> I used GridLayout with two columns.
> The scheme is as folowing:
> date label (1. column) | concrete date (2. column)
> descr label | description text
> An example:
> ...
> date: 09.25.04
> description: Now a longer description which
> contains many words.
>
> date: 09.28.04
> description: Now a longer description which
> contains many words.
> ...
>
> The problem is the label with the description, which needs
> often more than one row. I need a multi line label but SWT
> declared SWT.MULTI not for labels.
> Thats why, I tried a text field with text.setEnabled(false);
> for showing the description. But that causes two problems:
>
> 1. I have to set the height of the description text field so
> that the height is sufficient but not bigger.
> GridData.FILL_VERTICAL lets free space and gridData.heighHint
> demands the optimal height of the label which I don't know.
> I tried also with pack() but had no success.
>
> 2. The font looks disabled and because I set
> setEnabled(false) setForeGround(black) and so on has no
> effect.
>
> That seems to be a simple problem but I searched a solution
> for a long time without result. Does anybody know how I
> can display multi line labels?
>
> Regards, Tobi
>
> ************************************************************ ****
>
> text = new Text(shell, SWT.MULTI | SWT.WRAP);
> text.setEnabled(false);
> text.setText(buffer.toString());
> gridData = new GridData(GridData.FILL_HORIZONTAL
> | GridData.FILL_VERTICAL);
> text.setLayoutData(gridData);
>
>
>
Re: Multi line label [message #443692 is a reply to message #443689] Wed, 29 September 2004 10:57 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 21
Registered: July 2009
Junior Member
Hi Richard,

thank you for your answer. I also tried:
text.setEditable(false);
text.setBackground(white);
instead:
text.setEnabled(false);

Then the background and foreground color is ok but
the text has a cursor and can marked.

While the problem 2 is 'only' ugly, the first one is more important
because the app is for Pocket PC and there space is thinly distributed.

Regards, Tobi


"Richard Moore" <rmoore@infometis.ch> schrieb im Newsbeitrag
news:cje0mk$3hg$1@eclipse.org...
> Hi Tobi,
>
> Try using a text and setting the editable to false, you could even change
> the background color to gray... looks like a label then... I think setting
> enable to false stops the scrolling of a text ? editable I do not know if
> the scrolling still works... try it out.
>
> Regards
> Richard
>
>
> "Tobi Wink" <tobi.winkesf@lycos.com> wrote in message
> news:cjck1d$uh1$1@eclipse.org...
>> Hello,
>>
>> I have to show some name value pairs in a dialog.
>> The dialog has a fixed size (PPC).
>> I used GridLayout with two columns.
>> The scheme is as folowing:
>> date label (1. column) | concrete date (2. column)
>> descr label | description text
>> An example:
>> ...
>> date: 09.25.04
>> description: Now a longer description which
>> contains many words.
>>
>> date: 09.28.04
>> description: Now a longer description which
>> contains many words.
>> ...
>>
>> The problem is the label with the description, which needs
>> often more than one row. I need a multi line label but SWT
>> declared SWT.MULTI not for labels.
>> Thats why, I tried a text field with text.setEnabled(false);
>> for showing the description. But that causes two problems:
>>
>> 1. I have to set the height of the description text field so
>> that the height is sufficient but not bigger.
>> GridData.FILL_VERTICAL lets free space and gridData.heighHint
>> demands the optimal height of the label which I don't know.
>> I tried also with pack() but had no success.
>>
>> 2. The font looks disabled and because I set
>> setEnabled(false) setForeGround(black) and so on has no
>> effect.
>>
>> That seems to be a simple problem but I searched a solution
>> for a long time without result. Does anybody know how I
>> can display multi line labels?
>>
>> Regards, Tobi
>>
>> ************************************************************ ****
>>
>> text = new Text(shell, SWT.MULTI | SWT.WRAP);
>> text.setEnabled(false);
>> text.setText(buffer.toString());
>> gridData = new GridData(GridData.FILL_HORIZONTAL
>> | GridData.FILL_VERTICAL);
>> text.setLayoutData(gridData);
>>
>>
>>
>
>
Re: Multi line label [message #443696 is a reply to message #443692] Wed, 29 September 2004 12:04 Go to previous messageGo to next message
Benjamin Pasero is currently offline Benjamin PaseroFriend
Messages: 337
Registered: July 2009
Senior Member
Here is a possible solution that is using the StyledText widget
from the SWT custom package:

public class Main {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());

final StyledText st = new StyledText(shell, SWT.MULTI | SWT.READ_ONLY);
st.setText("Hello World");
st.setCursor(display.getSystemCursor(SWT.CURSOR_ARROW));
st.setCaret(null);

st.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
st.setSelection(0);
}
});

shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}

Just set the background to gray or something like that.

> Hi Richard,

> thank you for your answer. I also tried:
> text.setEditable(false);
> text.setBackground(white);
> instead:
> text.setEnabled(false);

> Then the background and foreground color is ok but
> the text has a cursor and can marked.

> While the problem 2 is 'only' ugly, the first one is more important
> because the app is for Pocket PC and there space is thinly distributed.

> Regards, Tobi


> "Richard Moore" <rmoore@infometis.ch> schrieb im Newsbeitrag
> news:cje0mk$3hg$1@eclipse.org...
> > Hi Tobi,
> >
> > Try using a text and setting the editable to false, you could even change
> > the background color to gray... looks like a label then... I think setting
> > enable to false stops the scrolling of a text ? editable I do not know if
> > the scrolling still works... try it out.
> >
> > Regards
> > Richard
> >
> >
> > "Tobi Wink" <tobi.winkesf@lycos.com> wrote in message
> > news:cjck1d$uh1$1@eclipse.org...
> >> Hello,
> >>
> >> I have to show some name value pairs in a dialog.
> >> The dialog has a fixed size (PPC).
> >> I used GridLayout with two columns.
> >> The scheme is as folowing:
> >> date label (1. column) | concrete date (2. column)
> >> descr label | description text
> >> An example:
> >> ...
> >> date: 09.25.04
> >> description: Now a longer description which
> >> contains many words.
> >>
> >> date: 09.28.04
> >> description: Now a longer description which
> >> contains many words.
> >> ...
> >>
> >> The problem is the label with the description, which needs
> >> often more than one row. I need a multi line label but SWT
> >> declared SWT.MULTI not for labels.
> >> Thats why, I tried a text field with text.setEnabled(false);
> >> for showing the description. But that causes two problems:
> >>
> >> 1. I have to set the height of the description text field so
> >> that the height is sufficient but not bigger.
> >> GridData.FILL_VERTICAL lets free space and gridData.heighHint
> >> demands the optimal height of the label which I don't know.
> >> I tried also with pack() but had no success.
> >>
> >> 2. The font looks disabled and because I set
> >> setEnabled(false) setForeGround(black) and so on has no
> >> effect.
> >>
> >> That seems to be a simple problem but I searched a solution
> >> for a long time without result. Does anybody know how I
> >> can display multi line labels?
> >>
> >> Regards, Tobi
> >>
> >> ************************************************************ ****
> >>
> >> text = new Text(shell, SWT.MULTI | SWT.WRAP);
> >> text.setEnabled(false);
> >> text.setText(buffer.toString());
> >> gridData = new GridData(GridData.FILL_HORIZONTAL
> >> | GridData.FILL_VERTICAL);
> >> text.setLayoutData(gridData);
> >>
> >>
> >>
> >
> >
Re: Multi line label [message #443719 is a reply to message #443631] Wed, 29 September 2004 17:35 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
Why not just use SWT.WRAP for your label?

"Tobi Wink" <tobi.winkesf@lycos.com> wrote in message
news:cjck1d$uh1$1@eclipse.org...
> Hello,
>
> I have to show some name value pairs in a dialog.
> The dialog has a fixed size (PPC).
> I used GridLayout with two columns.
> The scheme is as folowing:
> date label (1. column) | concrete date (2. column)
> descr label | description text
> An example:
> ...
> date: 09.25.04
> description: Now a longer description which
> contains many words.
>
> date: 09.28.04
> description: Now a longer description which
> contains many words.
> ...
>
> The problem is the label with the description, which needs
> often more than one row. I need a multi line label but SWT
> declared SWT.MULTI not for labels.
> Thats why, I tried a text field with text.setEnabled(false);
> for showing the description. But that causes two problems:
>
> 1. I have to set the height of the description text field so
> that the height is sufficient but not bigger.
> GridData.FILL_VERTICAL lets free space and gridData.heighHint
> demands the optimal height of the label which I don't know.
> I tried also with pack() but had no success.
>
> 2. The font looks disabled and because I set
> setEnabled(false) setForeGround(black) and so on has no
> effect.
>
> That seems to be a simple problem but I searched a solution
> for a long time without result. Does anybody know how I
> can display multi line labels?
>
> Regards, Tobi
>
> ************************************************************ ****
>
> text = new Text(shell, SWT.MULTI | SWT.WRAP);
> text.setEnabled(false);
> text.setText(buffer.toString());
> gridData = new GridData(GridData.FILL_HORIZONTAL
> | GridData.FILL_VERTICAL);
> text.setLayoutData(gridData);
>
>
>
Re: Multi line label [message #443722 is a reply to message #443719] Wed, 29 September 2004 17:50 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 21
Registered: July 2009
Junior Member
"Steve Northover" <steve_northover@ca.ibm.com> schrieb im Newsbeitrag
news:cjergm$v7q$1@eclipse.org...
> Why not just use SWT.WRAP for your label?

That helps not much because then the label is one row high without settig
GridData.
And if I set gridData.heightHint=50 or so the label is often too big (or
better too many rows high). I need then an algorithm to
calculate this height.

Tobi
Re: Multi line label [message #443793 is a reply to message #443722] Thu, 30 September 2004 17:26 Go to previous message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
Why is the same algorithm not necessary using a Text control with SWT.WRAP.

"Tobi Wink" <tobi.winkesf@lycos.com> wrote in message
news:cjescp$1ab$1@eclipse.org...
>
> "Steve Northover" <steve_northover@ca.ibm.com> schrieb im Newsbeitrag
> news:cjergm$v7q$1@eclipse.org...
> > Why not just use SWT.WRAP for your label?
>
> That helps not much because then the label is one row high without settig
> GridData.
> And if I set gridData.heightHint=50 or so the label is often too big (or
> better too many rows high). I need then an algorithm to
> calculate this height.
>
> Tobi
>
>
Previous Topic:How to monitor changes to the Clipboard.
Next Topic:[PPC] A user friendly list
Goto Forum:
  


Current Time: Fri Apr 26 17:10:57 GMT 2024

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

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

Back to the top