Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » StyledText layout problem
StyledText layout problem [message #444076] Wed, 06 October 2004 17:33 Go to next message
Eclipse UserFriend
Originally posted by: jca.micromuse.com

I am trying to add multiple StyledText widgets to a single scrollable
widget. The idea is that I can add text to each StyledText and they
all scroll together within a single scrollbar. I am using multiple StyledTexts
because I will later add images between them. I have not found a way to embed images
to a StyledText widget.

This is the composite hierarchy I have right now :

Shell
ScrolledComposite
Group
StyledText1
StyledText2
......
......
StyledTextN


My problem is that even just having a single StyledText in the group does
not display across the entire window. The StyledText is only
big enough to display its text and I don't know how to set the size of
the StyledText, I have tried setSize() and setBounds() to large numbers
but that did not work, here is a code sample :

public Composite getComposite(final Composite aParentComposite)
{
gScrolledComposite = new ScrolledComposite(aParentComposite,
SWT.V_SCROLL | SWT.H_SCROLL);
gGroup = new Group(gScrolledComposite, SWT.SHADOW_NONE );
gScrolledComposite.setContent(gGroup);

aParentComposite.setBackground(new Color(gDisplay, 0, 255, 0));
gGroup.setBackground(new Color(gDisplay, 255, 0, 0));
RowLayout aRowLayout = new RowLayout(SWT.VERTICAL);
aRowLayout.wrap = false;
aRowLayout.spacing = 0;
gGroup.setLayout(aRowLayout);

StyledText aStyledText = new StyledText(gGroup, SWT.NONE);
aStyledText.setText("xxx");
aStyledText.setSize(600, 400);
gGroup.layout(true);

gGroup.setSize(600, gGroup.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).y);
return gScrolledComposite;
}

SO all I get is a StyledText that displays 'xxx' and which does not
have room for me to add any more text.

Any help is much appreciated,

thanks,

John.
Re: StyledText layout problem [message #444151 is a reply to message #444076] Thu, 07 October 2004 20:23 Go to previous messageGo to next message
Lynne Kues is currently offline Lynne KuesFriend
Messages: 1
Registered: July 2009
Junior Member
Since you're using layouts, you need to specify any sizes in the layout data
for the widget. Something like the following should work:

public static void main(String[] args) {
Test test = new Test();
Shell shell = new Shell(SWT.TITLE | SWT.MENU | SWT.MIN | SWT.RESIZE |
SWT.MAX);
shell.setLayout(new RowLayout(SWT.VERTICAL));
Composite group = new Composite(shell, SWT.NULL);
group.setLayout(new RowLayout());
StyledText text = new StyledText(group, SWT.NONE);
text.setText("xxx");
RowData data = new RowData();
data.height = 400;
data.width = 600;
text.setLayoutData(data);
shell.pack();
shell.open();
Display display = shell.getDisplay();
while (!shell.isDisposed())
if (!display.readAndDispatch())
display.sleep();
display.dispose();
}

"John Carroll" <jca@micromuse.com> wrote in message
news:ck19tb$sm9$1@eclipse.org...
> I am trying to add multiple StyledText widgets to a single scrollable
> widget. The idea is that I can add text to each StyledText and they
> all scroll together within a single scrollbar. I am using multiple
StyledTexts
> because I will later add images between them. I have not found a way to
embed images
> to a StyledText widget.
>
> This is the composite hierarchy I have right now :
>
> Shell
> ScrolledComposite
> Group
> StyledText1
> StyledText2
> ......
> ......
> StyledTextN
>
>
> My problem is that even just having a single StyledText in the group does
> not display across the entire window. The StyledText is only
> big enough to display its text and I don't know how to set the size of
> the StyledText, I have tried setSize() and setBounds() to large numbers
> but that did not work, here is a code sample :
>
> public Composite getComposite(final Composite aParentComposite)
> {
> gScrolledComposite = new ScrolledComposite(aParentComposite,
> SWT.V_SCROLL | SWT.H_SCROLL);
> gGroup = new Group(gScrolledComposite, SWT.SHADOW_NONE );
> gScrolledComposite.setContent(gGroup);
>
> aParentComposite.setBackground(new Color(gDisplay, 0, 255, 0));
> gGroup.setBackground(new Color(gDisplay, 255, 0, 0));
> RowLayout aRowLayout = new RowLayout(SWT.VERTICAL);
> aRowLayout.wrap = false;
> aRowLayout.spacing = 0;
> gGroup.setLayout(aRowLayout);
>
> StyledText aStyledText = new StyledText(gGroup, SWT.NONE);
> aStyledText.setText("xxx");
> aStyledText.setSize(600, 400);
> gGroup.layout(true);
>
> gGroup.setSize(600, gGroup.computeSize(SWT.DEFAULT, SWT.DEFAULT,
true).y);
> return gScrolledComposite;
> }
>
> SO all I get is a StyledText that displays 'xxx' and which does not
> have room for me to add any more text.
>
> Any help is much appreciated,
>
> thanks,
>
> John.
>
Re: StyledText layout problem [message #444192 is a reply to message #444151] Fri, 08 October 2004 13:42 Go to previous message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
If you don't want to hard code widths, you can use GridLayout or FormLayout:

public static void main (String [] args) {
Display display = new Display ();
Image image = new Image(display,
Newsgroup.class.getResourceAsStream("../images/image.bmp"));
Shell shell = new Shell (display);
shell.setLayout(new FillLayout());
ScrolledComposite sc = new ScrolledComposite(shell, SWT.V_SCROLL |
SWT.H_SCROLL);
Composite c = new Composite(sc, SWT.NONE);
c.setLayout(new GridLayout());
for (int i = 0; i < 10; i++) {
StyledText text = new StyledText(c, SWT.MULTI | SWT.WRAP |
SWT.BORDER);
text.setText("paragraph 1");
GridData data = new GridData(SWT.FILL, SWT.TOP, true,
false);
data.heightHint = 50;
text.setLayoutData(data);
Label label = new Label(c, SWT.NONE);
label.setImage(image);
label.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, false,
false));
label = new Label(c, SWT.NONE);
label.setText("Figure "+i);
label.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, false,
false));
}
c.layout();
sc.setContent(c);
Point size = c.computeSize(SWT.DEFAULT, SWT.DEFAULT);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setMinSize(size);
shell.setSize(400, 300);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}

"Lynne Kues" <lynne_kues@oti.com> wrote in message
news:ck48b2$6o7$1@eclipse.org...
> Since you're using layouts, you need to specify any sizes in the layout
> data
> for the widget. Something like the following should work:
>
> public static void main(String[] args) {
> Test test = new Test();
> Shell shell = new Shell(SWT.TITLE | SWT.MENU | SWT.MIN | SWT.RESIZE |
> SWT.MAX);
> shell.setLayout(new RowLayout(SWT.VERTICAL));
> Composite group = new Composite(shell, SWT.NULL);
> group.setLayout(new RowLayout());
> StyledText text = new StyledText(group, SWT.NONE);
> text.setText("xxx");
> RowData data = new RowData();
> data.height = 400;
> data.width = 600;
> text.setLayoutData(data);
> shell.pack();
> shell.open();
> Display display = shell.getDisplay();
> while (!shell.isDisposed())
> if (!display.readAndDispatch())
> display.sleep();
> display.dispose();
> }
>
> "John Carroll" <jca@micromuse.com> wrote in message
> news:ck19tb$sm9$1@eclipse.org...
>> I am trying to add multiple StyledText widgets to a single scrollable
>> widget. The idea is that I can add text to each StyledText and they
>> all scroll together within a single scrollbar. I am using multiple
> StyledTexts
>> because I will later add images between them. I have not found a way to
> embed images
>> to a StyledText widget.
>>
>> This is the composite hierarchy I have right now :
>>
>> Shell
>> ScrolledComposite
>> Group
>> StyledText1
>> StyledText2
>> ......
>> ......
>> StyledTextN
>>
>>
>> My problem is that even just having a single StyledText in the group does
>> not display across the entire window. The StyledText is only
>> big enough to display its text and I don't know how to set the size of
>> the StyledText, I have tried setSize() and setBounds() to large numbers
>> but that did not work, here is a code sample :
>>
>> public Composite getComposite(final Composite aParentComposite)
>> {
>> gScrolledComposite = new ScrolledComposite(aParentComposite,
>> SWT.V_SCROLL | SWT.H_SCROLL);
>> gGroup = new Group(gScrolledComposite, SWT.SHADOW_NONE );
>> gScrolledComposite.setContent(gGroup);
>>
>> aParentComposite.setBackground(new Color(gDisplay, 0, 255, 0));
>> gGroup.setBackground(new Color(gDisplay, 255, 0, 0));
>> RowLayout aRowLayout = new RowLayout(SWT.VERTICAL);
>> aRowLayout.wrap = false;
>> aRowLayout.spacing = 0;
>> gGroup.setLayout(aRowLayout);
>>
>> StyledText aStyledText = new StyledText(gGroup, SWT.NONE);
>> aStyledText.setText("xxx");
>> aStyledText.setSize(600, 400);
>> gGroup.layout(true);
>>
>> gGroup.setSize(600, gGroup.computeSize(SWT.DEFAULT, SWT.DEFAULT,
> true).y);
>> return gScrolledComposite;
>> }
>>
>> SO all I get is a StyledText that displays 'xxx' and which does not
>> have room for me to add any more text.
>>
>> Any help is much appreciated,
>>
>> thanks,
>>
>> John.
>>
>
>
Previous Topic:How do I get disk space, free %, etc. plz
Next Topic:ComboBox on TableItem
Goto Forum:
  


Current Time: Tue Oct 27 23:59:27 GMT 2020

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

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

Back to the top