Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » [Styled Text] Layout problem
[Styled Text] Layout problem [message #439706] Wed, 14 July 2004 21:07 Go to next message
Eclipse UserFriend
Originally posted by: friederich.kupzog.de

Hello SWT people,

currently i am working on a help system for my application. It shows
formatted texts in diverse StyledText widgets with SWT.WRAP style.

If i use SWT 2.1, i encounter problem 1: the size of bold-font words in
a line is not correctly calculated, so words get truncated in the end of
lines.

So, i tried SWT 3.0 (Build id: 200405290105) and wow! the problem was
gone. BUT: now the StyledText widgets are always only one line high.
I use GridLayout and GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL
| GridData.VERTICAL_ALIGN_BEGINNING but you can be shure i experimented
with a lot of other combinations.

Has anyone a solution? Here is a snippet. Try it with SWT 2.1 and 3.0.

------------------------------------------------------------ --------------
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

/**
* @author Friederich Kupzog
*
*/
/**
* @author Friederich Kupzog
*/
public class Snippet
{


protected Shell shell;
protected Composite guiContentComposite;
protected ScrolledComposite scroll;

public static void main(String[] args) {
Snippet window = new Snippet();
window.open();
}


public void open() {

Display display;
display = new Display();


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

protected void createContents() {
shell = new Shell();
shell.setLayout(new FillLayout());
scroll = new ScrolledComposite(shell, SWT.V_SCROLL | SWT.H_SCROLL);

guiContentComposite = new Composite(scroll, SWT.NONE);
scroll.setContent(guiContentComposite);
scroll.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent arg0) {
layoutArticle();
}
});
scroll.setBackground(Display.getCurrent().getSystemColor(SWT .COLOR_GRAY));

guiContentComposite.setBackground(Display.getCurrent().getSy stemColor(SWT.COLOR_YELLOW));
guiContentComposite.setLayout(new GridLayout(2, false));

// generate some example contents
generateSWTForm(guiContentComposite);
generateSWTForm(guiContentComposite);
generateSWTForm(guiContentComposite);

}

final static int marginPixel = 100;

public void generateSWTForm(Composite parent) {
Label margin = new Label(parent, SWT.WRAP);
GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
gd.widthHint = marginPixel;

margin.setBackground(Display.getCurrent().getSystemColor(SWT .COLOR_WHITE));
margin.setText("This is margintext");
margin.setLayoutData(gd);

final StyledText main = new StyledText(parent, SWT.WRAP);
main.setEditable(false);
main.setEnabled(false);

main.setFont(new Font(Display.getCurrent(), "Arial", 12, SWT.NONE));
// ok, should dispose it sometime...

main.setBackground(Display.getCurrent().getSystemColor(SWT.C OLOR_WHITE));
main.setText("In SWT 2.1, the first line gets truncated. " +
"So, i tried SWT 3.0 (Build id: 200405290105) and wow! the problem" +
" was gone. BUT: now the StyledText widgets are always only one line
high." +
" I use GridLayout and GridData.GRAB_HORIZONTAL |
GridData.FILL_HORIZONTAL" +
" | GridData.VERTICAL_ALIGN_BEGINNING but you can be shure i
experimented " +
"with a lot of other combinations. ");
gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL
| GridData.VERTICAL_ALIGN_BEGINNING);
main.setLayoutData(gd);

// some bold text:
StyleRange sr = new StyleRange();
sr.background = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
sr.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
sr.fontStyle = SWT.BOLD;
sr.start = 0;
sr.length = 30;
main.setStyleRange(sr);

}


protected void layoutArticle()
{
int width = Math.max(scroll.getSize().x-16,400);
guiContentComposite.layout();
guiContentComposite.setSize(
guiContentComposite.computeSize(width,
SWT.DEFAULT));
// need this final call because of wired behaviour in certain situations:
guiContentComposite.layout();
}


}
Re: [Styled Text] Layout problem [message #439747 is a reply to message #439706] Thu, 15 July 2004 16:32 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
Not sure how this was working in 2.1 but you need to set a width hint to
force the wrapping to work. I did this and the code works:

gd.widthHint = 200;

See also https://bugs.eclipse.org/bugs/show_bug.cgi?id=9866

"Friederich Kupzog" <friederich@kupzog.de> wrote in message
news:cd478f$dqt$1@eclipse.org...
> Hello SWT people,
>
> currently i am working on a help system for my application. It shows
> formatted texts in diverse StyledText widgets with SWT.WRAP style.
>
> If i use SWT 2.1, i encounter problem 1: the size of bold-font words in
> a line is not correctly calculated, so words get truncated in the end of
> lines.
>
> So, i tried SWT 3.0 (Build id: 200405290105) and wow! the problem was
> gone. BUT: now the StyledText widgets are always only one line high.
> I use GridLayout and GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL
> | GridData.VERTICAL_ALIGN_BEGINNING but you can be shure i experimented
> with a lot of other combinations.
>
> Has anyone a solution? Here is a snippet. Try it with SWT 2.1 and 3.0.
>
> ------------------------------------------------------------ --------------
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.custom.ScrolledComposite;
> import org.eclipse.swt.custom.StyleRange;
> import org.eclipse.swt.custom.StyledText;
> import org.eclipse.swt.events.ControlAdapter;
> import org.eclipse.swt.events.ControlEvent;
> import org.eclipse.swt.graphics.Font;
> import org.eclipse.swt.layout.*;
> import org.eclipse.swt.widgets.*;
>
> /**
> * @author Friederich Kupzog
> *
> */
> /**
> * @author Friederich Kupzog
> */
> public class Snippet
> {
>
>
> protected Shell shell;
> protected Composite guiContentComposite;
> protected ScrolledComposite scroll;
>
> public static void main(String[] args) {
> Snippet window = new Snippet();
> window.open();
> }
>
>
> public void open() {
>
> Display display;
> display = new Display();
>
>
> createContents();
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> }
>
> protected void createContents() {
> shell = new Shell();
> shell.setLayout(new FillLayout());
> scroll = new ScrolledComposite(shell, SWT.V_SCROLL | SWT.H_SCROLL);
>
> guiContentComposite = new Composite(scroll, SWT.NONE);
> scroll.setContent(guiContentComposite);
> scroll.addControlListener(new ControlAdapter() {
> public void controlResized(ControlEvent arg0) {
> layoutArticle();
> }
> });
> scroll.setBackground(Display.getCurrent().getSystemColor(SWT .COLOR_GRAY));
>
>
guiContentComposite.setBackground(Display.getCurrent().getSy stemColor(SWT.CO
LOR_YELLOW));
> guiContentComposite.setLayout(new GridLayout(2, false));
>
> // generate some example contents
> generateSWTForm(guiContentComposite);
> generateSWTForm(guiContentComposite);
> generateSWTForm(guiContentComposite);
>
> }
>
> final static int marginPixel = 100;
>
> public void generateSWTForm(Composite parent) {
> Label margin = new Label(parent, SWT.WRAP);
> GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
> gd.widthHint = marginPixel;
>
>
margin.setBackground(Display.getCurrent().getSystemColor(SWT .COLOR_WHITE));
> margin.setText("This is margintext");
> margin.setLayoutData(gd);
>
> final StyledText main = new StyledText(parent, SWT.WRAP);
> main.setEditable(false);
> main.setEnabled(false);
>
> main.setFont(new Font(Display.getCurrent(), "Arial", 12, SWT.NONE));
> // ok, should dispose it sometime...
>
> main.setBackground(Display.getCurrent().getSystemColor(SWT.C OLOR_WHITE));
> main.setText("In SWT 2.1, the first line gets truncated. " +
> "So, i tried SWT 3.0 (Build id: 200405290105) and wow! the problem" +
> " was gone. BUT: now the StyledText widgets are always only one line
> high." +
> " I use GridLayout and GridData.GRAB_HORIZONTAL |
> GridData.FILL_HORIZONTAL" +
> " | GridData.VERTICAL_ALIGN_BEGINNING but you can be shure i
> experimented " +
> "with a lot of other combinations. ");
> gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL
> | GridData.VERTICAL_ALIGN_BEGINNING);
> main.setLayoutData(gd);
>
> // some bold text:
> StyleRange sr = new StyleRange();
> sr.background = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
> sr.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
> sr.fontStyle = SWT.BOLD;
> sr.start = 0;
> sr.length = 30;
> main.setStyleRange(sr);
>
> }
>
>
> protected void layoutArticle()
> {
> int width = Math.max(scroll.getSize().x-16,400);
> guiContentComposite.layout();
> guiContentComposite.setSize(
> guiContentComposite.computeSize(width,
> SWT.DEFAULT));
> // need this final call because of wired behaviour in certain situations:
> guiContentComposite.layout();
> }
>
>
> }
Re: [Styled Text] Layout problem [message #439834 is a reply to message #439747] Fri, 16 July 2004 15:14 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: friederich.kupzog.de

So, if I want a dynamic text wrappig that changes with the width of the
scrolled composite, I need to hold all GridData in a list and change the
width hint each time a resize occurs?

Or is there a simpler solution?

Thanks so far
Friederich


Steve Northover wrote:
> Not sure how this was working in 2.1 but you need to set a width hint to
> force the wrapping to work. I did this and the code works:
>
> gd.widthHint = 200;
>
> See also https://bugs.eclipse.org/bugs/show_bug.cgi?id=9866
>
> "Friederich Kupzog" <friederich@kupzog.de> wrote in message
> news:cd478f$dqt$1@eclipse.org...
>
>>Hello SWT people,
>>
>>currently i am working on a help system for my application. It shows
>>formatted texts in diverse StyledText widgets with SWT.WRAP style.
>>
>>If i use SWT 2.1, i encounter problem 1: the size of bold-font words in
>>a line is not correctly calculated, so words get truncated in the end of
>>lines.
>>
>>So, i tried SWT 3.0 (Build id: 200405290105) and wow! the problem was
>>gone. BUT: now the StyledText widgets are always only one line high.
>>I use GridLayout and GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL
>>| GridData.VERTICAL_ALIGN_BEGINNING but you can be shure i experimented
>>with a lot of other combinations.
>>
>>Has anyone a solution? Here is a snippet. Try it with SWT 2.1 and 3.0.
>>
>> ------------------------------------------------------------ --------------
>>import org.eclipse.swt.SWT;
>>import org.eclipse.swt.custom.ScrolledComposite;
>>import org.eclipse.swt.custom.StyleRange;
>>import org.eclipse.swt.custom.StyledText;
>>import org.eclipse.swt.events.ControlAdapter;
>>import org.eclipse.swt.events.ControlEvent;
>>import org.eclipse.swt.graphics.Font;
>>import org.eclipse.swt.layout.*;
>>import org.eclipse.swt.widgets.*;
>>
>>/**
>> * @author Friederich Kupzog
>> *
>> */
>>/**
>> * @author Friederich Kupzog
>> */
>>public class Snippet
>>{
>>
>>
>>protected Shell shell;
>>protected Composite guiContentComposite;
>>protected ScrolledComposite scroll;
>>
>>public static void main(String[] args) {
>>Snippet window = new Snippet();
>>window.open();
>>}
>>
>>
>>public void open() {
>>
>>Display display;
>>display = new Display();
>>
>>
>>createContents();
>>shell.open();
>>while (!shell.isDisposed()) {
>>if (!display.readAndDispatch())
>>display.sleep();
>>}
>>}
>>
>>protected void createContents() {
>>shell = new Shell();
>>shell.setLayout(new FillLayout());
>>scroll = new ScrolledComposite(shell, SWT.V_SCROLL | SWT.H_SCROLL);
>>
>>guiContentComposite = new Composite(scroll, SWT.NONE);
>>scroll.setContent(guiContentComposite);
>>scroll.addControlListener(new ControlAdapter() {
>>public void controlResized(ControlEvent arg0) {
>>layoutArticle();
>>}
>>});
>> scroll.setBackground(Display.getCurrent().getSystemColor(SWT .COLOR_GRAY));
>>
>>
>
> guiContentComposite.setBackground(Display.getCurrent().getSy stemColor(SWT.CO
> LOR_YELLOW));
>
>>guiContentComposite.setLayout(new GridLayout(2, false));
>>
>>// generate some example contents
>>generateSWTForm(guiContentComposite);
>>generateSWTForm(guiContentComposite);
>>generateSWTForm(guiContentComposite);
>>
>>}
>>
>>final static int marginPixel = 100;
>>
>>public void generateSWTForm(Composite parent) {
>>Label margin = new Label(parent, SWT.WRAP);
>>GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
>>gd.widthHint = marginPixel;
>>
>>
>
> margin.setBackground(Display.getCurrent().getSystemColor(SWT .COLOR_WHITE));
>
>>margin.setText("This is margintext");
>>margin.setLayoutData(gd);
>>
>>final StyledText main = new StyledText(parent, SWT.WRAP);
>>main.setEditable(false);
>>main.setEnabled(false);
>>
>>main.setFont(new Font(Display.getCurrent(), "Arial", 12, SWT.NONE));
>>// ok, should dispose it sometime...
>>
>> main.setBackground(Display.getCurrent().getSystemColor(SWT.C OLOR_WHITE));
>>main.setText("In SWT 2.1, the first line gets truncated. " +
>>"So, i tried SWT 3.0 (Build id: 200405290105) and wow! the problem" +
>>" was gone. BUT: now the StyledText widgets are always only one line
>>high." +
>>" I use GridLayout and GridData.GRAB_HORIZONTAL |
>>GridData.FILL_HORIZONTAL" +
>>" | GridData.VERTICAL_ALIGN_BEGINNING but you can be shure i
>>experimented " +
>>"with a lot of other combinations. ");
>>gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL
>>| GridData.VERTICAL_ALIGN_BEGINNING);
>>main.setLayoutData(gd);
>>
>>// some bold text:
>>StyleRange sr = new StyleRange();
>>sr.background = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
>>sr.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
>>sr.fontStyle = SWT.BOLD;
>>sr.start = 0;
>>sr.length = 30;
>>main.setStyleRange(sr);
>>
>>}
>>
>>
>>protected void layoutArticle()
>>{
>>int width = Math.max(scroll.getSize().x-16,400);
>>guiContentComposite.layout();
>>guiContentComposite.setSize(
>>guiContentComposite.computeSize(width,
>>SWT.DEFAULT));
>>// need this final call because of wired behaviour in certain situations:
>>guiContentComposite.layout();
>>}
>>
>>
>>}
>
>
>


--
Friederich Kupzog
Elektronik & Software
Neusser Str. 5-7
50670 Köln
Tel 0241 160696-1
Fax 0221 726670
www.kupzog.de/fkmk
Re: [Styled Text] Layout problem [message #439915 is a reply to message #439834] Mon, 19 July 2004 16:23 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
Not for now. We are working on a better solution but the problem is quite
complicated (believe it or not).

https://bugs.eclipse.org/bugs/show_bug.cgi?id=9866

"Friederich Kupzog" <friederich@kupzog.de> wrote in message
news:cd8r9n$q90$1@eclipse.org...
> So, if I want a dynamic text wrappig that changes with the width of the
> scrolled composite, I need to hold all GridData in a list and change the
> width hint each time a resize occurs?
>
> Or is there a simpler solution?
>
> Thanks so far
> Friederich
>
>
> Steve Northover wrote:
> > Not sure how this was working in 2.1 but you need to set a width hint to
> > force the wrapping to work. I did this and the code works:
> >
> > gd.widthHint = 200;
> >
> > See also https://bugs.eclipse.org/bugs/show_bug.cgi?id=9866
> >
> > "Friederich Kupzog" <friederich@kupzog.de> wrote in message
> > news:cd478f$dqt$1@eclipse.org...
> >
> >>Hello SWT people,
> >>
> >>currently i am working on a help system for my application. It shows
> >>formatted texts in diverse StyledText widgets with SWT.WRAP style.
> >>
> >>If i use SWT 2.1, i encounter problem 1: the size of bold-font words in
> >>a line is not correctly calculated, so words get truncated in the end of
> >>lines.
> >>
> >>So, i tried SWT 3.0 (Build id: 200405290105) and wow! the problem was
> >>gone. BUT: now the StyledText widgets are always only one line high.
> >>I use GridLayout and GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL
> >>| GridData.VERTICAL_ALIGN_BEGINNING but you can be shure i experimented
> >>with a lot of other combinations.
> >>
> >>Has anyone a solution? Here is a snippet. Try it with SWT 2.1 and 3.0.
> >>
>
>> ------------------------------------------------------------ --------------
> >>import org.eclipse.swt.SWT;
> >>import org.eclipse.swt.custom.ScrolledComposite;
> >>import org.eclipse.swt.custom.StyleRange;
> >>import org.eclipse.swt.custom.StyledText;
> >>import org.eclipse.swt.events.ControlAdapter;
> >>import org.eclipse.swt.events.ControlEvent;
> >>import org.eclipse.swt.graphics.Font;
> >>import org.eclipse.swt.layout.*;
> >>import org.eclipse.swt.widgets.*;
> >>
> >>/**
> >> * @author Friederich Kupzog
> >> *
> >> */
> >>/**
> >> * @author Friederich Kupzog
> >> */
> >>public class Snippet
> >>{
> >>
> >>
> >>protected Shell shell;
> >>protected Composite guiContentComposite;
> >>protected ScrolledComposite scroll;
> >>
> >>public static void main(String[] args) {
> >>Snippet window = new Snippet();
> >>window.open();
> >>}
> >>
> >>
> >>public void open() {
> >>
> >>Display display;
> >>display = new Display();
> >>
> >>
> >>createContents();
> >>shell.open();
> >>while (!shell.isDisposed()) {
> >>if (!display.readAndDispatch())
> >>display.sleep();
> >>}
> >>}
> >>
> >>protected void createContents() {
> >>shell = new Shell();
> >>shell.setLayout(new FillLayout());
> >>scroll = new ScrolledComposite(shell, SWT.V_SCROLL | SWT.H_SCROLL);
> >>
> >>guiContentComposite = new Composite(scroll, SWT.NONE);
> >>scroll.setContent(guiContentComposite);
> >>scroll.addControlListener(new ControlAdapter() {
> >>public void controlResized(ControlEvent arg0) {
> >>layoutArticle();
> >>}
> >>});
>
>> scroll.setBackground(Display.getCurrent().getSystemColor(SWT .COLOR_GRAY));
> >>
> >>
> >
> >
guiContentComposite.setBackground(Display.getCurrent().getSy stemColor(SWT.CO
> > LOR_YELLOW));
> >
> >>guiContentComposite.setLayout(new GridLayout(2, false));
> >>
> >>// generate some example contents
> >>generateSWTForm(guiContentComposite);
> >>generateSWTForm(guiContentComposite);
> >>generateSWTForm(guiContentComposite);
> >>
> >>}
> >>
> >>final static int marginPixel = 100;
> >>
> >>public void generateSWTForm(Composite parent) {
> >>Label margin = new Label(parent, SWT.WRAP);
> >>GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
> >>gd.widthHint = marginPixel;
> >>
> >>
> >
> >
margin.setBackground(Display.getCurrent().getSystemColor(SWT .COLOR_WHITE));
> >
> >>margin.setText("This is margintext");
> >>margin.setLayoutData(gd);
> >>
> >>final StyledText main = new StyledText(parent, SWT.WRAP);
> >>main.setEditable(false);
> >>main.setEnabled(false);
> >>
> >>main.setFont(new Font(Display.getCurrent(), "Arial", 12, SWT.NONE));
> >>// ok, should dispose it sometime...
> >>
>
>> main.setBackground(Display.getCurrent().getSystemColor(SWT.C OLOR_WHITE));
> >>main.setText("In SWT 2.1, the first line gets truncated. " +
> >>"So, i tried SWT 3.0 (Build id: 200405290105) and wow! the problem" +
> >>" was gone. BUT: now the StyledText widgets are always only one line
> >>high." +
> >>" I use GridLayout and GridData.GRAB_HORIZONTAL |
> >>GridData.FILL_HORIZONTAL" +
> >>" | GridData.VERTICAL_ALIGN_BEGINNING but you can be shure i
> >>experimented " +
> >>"with a lot of other combinations. ");
> >>gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL
> >>| GridData.VERTICAL_ALIGN_BEGINNING);
> >>main.setLayoutData(gd);
> >>
> >>// some bold text:
> >>StyleRange sr = new StyleRange();
> >>sr.background = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
> >>sr.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
> >>sr.fontStyle = SWT.BOLD;
> >>sr.start = 0;
> >>sr.length = 30;
> >>main.setStyleRange(sr);
> >>
> >>}
> >>
> >>
> >>protected void layoutArticle()
> >>{
> >>int width = Math.max(scroll.getSize().x-16,400);
> >>guiContentComposite.layout();
> >>guiContentComposite.setSize(
> >>guiContentComposite.computeSize(width,
> >>SWT.DEFAULT));
> >>// need this final call because of wired behaviour in certain
situations:
> >>guiContentComposite.layout();
> >>}
> >>
> >>
> >>}
> >
> >
> >
>
>
> --
> Friederich Kupzog
> Elektronik & Software
> Neusser Str. 5-7
> 50670 K
Re: [Styled Text] Layout problem [message #440022 is a reply to message #439915] Wed, 21 July 2004 08:39 Go to previous message
Eclipse UserFriend
Originally posted by: friederich.kupzog.de

Ok, thank you.

Regards,
Friederich

Steve Northover wrote:
> Not for now. We are working on a better solution but the problem is quite
> complicated (believe it or not).
>
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=9866
>
> "Friederich Kupzog" <friederich@kupzog.de> wrote in message
> news:cd8r9n$q90$1@eclipse.org...
>
>>So, if I want a dynamic text wrappig that changes with the width of the
>>scrolled composite, I need to hold all GridData in a list and change the
>>width hint each time a resize occurs?
>>
>>Or is there a simpler solution?
>>
>>Thanks so far
>>Friederich
>>
>>
>>Steve Northover wrote:
>>
>>>Not sure how this was working in 2.1 but you need to set a width hint to
>>>force the wrapping to work. I did this and the code works:
>>>
>>> gd.widthHint = 200;
>>>
>>>See also https://bugs.eclipse.org/bugs/show_bug.cgi?id=9866
>>>
>>>"Friederich Kupzog" <friederich@kupzog.de> wrote in message
>>>news:cd478f$dqt$1@eclipse.org...
>>>
>>>
>>>>Hello SWT people,
>>>>
>>>>currently i am working on a help system for my application. It shows
>>>>formatted texts in diverse StyledText widgets with SWT.WRAP style.
>>>>
>>>>If i use SWT 2.1, i encounter problem 1: the size of bold-font words in
>>>>a line is not correctly calculated, so words get truncated in the end of
>>>>lines.
>>>>
>>>>So, i tried SWT 3.0 (Build id: 200405290105) and wow! the problem was
>>>>gone. BUT: now the StyledText widgets are always only one line high.
>>>>I use GridLayout and GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL
>>>>| GridData.VERTICAL_ALIGN_BEGINNING but you can be shure i experimented
>>>>with a lot of other combinations.
>>>>
>>>>Has anyone a solution? Here is a snippet. Try it with SWT 2.1 and 3.0.
>>>>
>>
>>> ------------------------------------------------------------ --------------
>>>
>>>>import org.eclipse.swt.SWT;
>>>>import org.eclipse.swt.custom.ScrolledComposite;
>>>>import org.eclipse.swt.custom.StyleRange;
>>>>import org.eclipse.swt.custom.StyledText;
>>>>import org.eclipse.swt.events.ControlAdapter;
>>>>import org.eclipse.swt.events.ControlEvent;
>>>>import org.eclipse.swt.graphics.Font;
>>>>import org.eclipse.swt.layout.*;
>>>>import org.eclipse.swt.widgets.*;
>>>>
>>>>/**
>>>> * @author Friederich Kupzog
>>>> *
>>>> */
>>>>/**
>>>> * @author Friederich Kupzog
>>>> */
>>>>public class Snippet
>>>>{
>>>>
>>>>
>>>>protected Shell shell;
>>>>protected Composite guiContentComposite;
>>>>protected ScrolledComposite scroll;
>>>>
>>>>public static void main(String[] args) {
>>>>Snippet window = new Snippet();
>>>>window.open();
>>>>}
>>>>
>>>>
>>>>public void open() {
>>>>
>>>>Display display;
>>>>display = new Display();
>>>>
>>>>
>>>>createContents();
>>>>shell.open();
>>>>while (!shell.isDisposed()) {
>>>>if (!display.readAndDispatch())
>>>>display.sleep();
>>>>}
>>>>}
>>>>
>>>>protected void createContents() {
>>>>shell = new Shell();
>>>>shell.setLayout(new FillLayout());
>>>>scroll = new ScrolledComposite(shell, SWT.V_SCROLL | SWT.H_SCROLL);
>>>>
>>>>guiContentComposite = new Composite(scroll, SWT.NONE);
>>>>scroll.setContent(guiContentComposite);
>>>>scroll.addControlListener(new ControlAdapter() {
>>>>public void controlResized(ControlEvent arg0) {
>>>>layoutArticle();
>>>>}
>>>>});
>>
>>> scroll.setBackground(Display.getCurrent().getSystemColor(SWT .COLOR_GRAY));
>>>
>>>>
>>>
> guiContentComposite.setBackground(Display.getCurrent().getSy stemColor(SWT.CO
>
>>>LOR_YELLOW));
>>>
>>>
>>>>guiContentComposite.setLayout(new GridLayout(2, false));
>>>>
>>>>// generate some example contents
>>>>generateSWTForm(guiContentComposite);
>>>>generateSWTForm(guiContentComposite);
>>>>generateSWTForm(guiContentComposite);
>>>>
>>>>}
>>>>
>>>>final static int marginPixel = 100;
>>>>
>>>>public void generateSWTForm(Composite parent) {
>>>>Label margin = new Label(parent, SWT.WRAP);
>>>>GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
>>>>gd.widthHint = marginPixel;
>>>>
>>>>
>>>
>>>
> margin.setBackground(Display.getCurrent().getSystemColor(SWT .COLOR_WHITE));
>
>>>>margin.setText("This is margintext");
>>>>margin.setLayoutData(gd);
>>>>
>>>>final StyledText main = new StyledText(parent, SWT.WRAP);
>>>>main.setEditable(false);
>>>>main.setEnabled(false);
>>>>
>>>>main.setFont(new Font(Display.getCurrent(), "Arial", 12, SWT.NONE));
>>>>// ok, should dispose it sometime...
>>>>
>>
>>> main.setBackground(Display.getCurrent().getSystemColor(SWT.C OLOR_WHITE));
>>>
>>>>main.setText("In SWT 2.1, the first line gets truncated. " +
>>>>"So, i tried SWT 3.0 (Build id: 200405290105) and wow! the problem" +
>>>>" was gone. BUT: now the StyledText widgets are always only one line
>>>>high." +
>>>>" I use GridLayout and GridData.GRAB_HORIZONTAL |
>>>>GridData.FILL_HORIZONTAL" +
>>>>" | GridData.VERTICAL_ALIGN_BEGINNING but you can be shure i
>>>>experimented " +
>>>>"with a lot of other combinations. ");
>>>>gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL
>>>>| GridData.VERTICAL_ALIGN_BEGINNING);
>>>>main.setLayoutData(gd);
>>>>
>>>>// some bold text:
>>>>StyleRange sr = new StyleRange();
>>>>sr.background = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
>>>>sr.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
>>>>sr.fontStyle = SWT.BOLD;
>>>>sr.start = 0;
>>>>sr.length = 30;
>>>>main.setStyleRange(sr);
>>>>
>>>>}
>>>>
>>>>
>>>>protected void layoutArticle()
>>>>{
>>>>int width = Math.max(scroll.getSize().x-16,400);
>>>>guiContentComposite.layout();
>>>>guiContentComposite.setSize(
>>>>guiContentComposite.computeSize(width,
>>>>SWT.DEFAULT));
>>>>// need this final call because of wired behaviour in certain
>
> situations:
>
>>>>guiContentComposite.layout();
>>>>}
>>>>
>>>>
>>>>}
>>>
>>>
>>>
>>
>>--
>>Friederich Kupzog
>>Elektronik & Software
>>Neusser Str. 5-7
>>50670 Köln
>>Tel 0241 160696-1
>>Fax 0221 726670
>>www.kupzog.de/fkmk
>
>
>


--
Friederich Kupzog
Elektronik & Software
Neusser Str. 5-7
50670 Köln
Tel 0241 160696-1
Fax 0221 726670
www.kupzog.de/fkmk
Previous Topic:Thin client and grid computing
Next Topic:Not getting Ole events from Word
Goto Forum:
  


Current Time: Fri Mar 29 08:37:16 GMT 2024

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

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

Back to the top