Wrap Text [message #176309] |
Fri, 08 April 2005 19:16  |
Eclipse User |
|
|
|
Originally posted by: jsk_lam.hotmail.com
Hi,
I have a org.eclipse.draw2d.Label and would like to have the text wrapped
around to next line if the box is not wide enough to fit the string.
Would someone please help and show me what do I need to do?
Thanks
sl
|
|
|
|
|
|
|
|
|
|
Re: Wrap Text [message #176574 is a reply to message #176437] |
Sun, 10 April 2005 20:18   |
Eclipse User |
|
|
|
Originally posted by: jsk_lam.hotmail.com
Yes, no text appears and no error or exception until all figures are
created,
then the exceptions occured. I am using the ToolbarLayout.
I tried to use FlowLayout, but the layout becomes
+----------------+
| Icon Text Icon |
+----------------+
This is not the way I want.
"Pratik Shah" <ppshah@us.ibm.com> wrote in message
news:d3c8af$oan$1@news.eclipse.org...
> And you're saying no text appears now that you're using a FlowPage? Are
you
> using a ToolbarLayout for your panel?
>
> This should be simple to debug yourself. You're doing something basic
> wrong.
>
> "slam" <jsk_lam@hotmail.com> wrote in message
> news:d3c6hs$mm4$1@news.eclipse.org...
> > I do need the panel, it is the container of 3 figures:
> >
> > +------+
> > | Icon |
> > | Text |
> > | Icon |
> > +------+
> >
> > "Pratik Shah" <ppshah@us.ibm.com> wrote in message
> > news:d3bj64$rg$1@news.eclipse.org...
> > > That would depend on the layout of the panel. But if you just want to
> > > display that text, you don't need the panel.
> > >
> > > "slam" <jsk_lam@hotmail.com> wrote in message
> > > news:d3bel5$rm6$1@news.eclipse.org...
> > > > Well, the text does not even show up in the panel with FlowPage.
> > > >
> > > > "Lorenz Maierhofer" <lorenz.m@gmx.at> wrote in message
> > > > news:d38uc3$8jt$1@news.eclipse.org...
> > > > > Hi,
> > > > >
> > > > > Just don't use Label, but something like:
> > > > >
> > > > > TextFlow content = new TextFlow("TExt to wrap");
> > > > > FlowPage fp = new FlowPage();
> > > > > fp.add(content);
> > > > > Panel panel = new Panel(); // My panel contains multiple
figures.
> > > > > panel.add(fp);
> > > > > add(panel);
> > > > >
> > > > >
> > > > >
> > > > > > This is what I did:
> > > > > > Label label = new Label();
> > > > > > TextFlow textFlow = new TextFlow(node.getLabel());
> > > > > > label.add(textFlow);
> > > > > > Panel panel = new Panel(); // My panel contains multiple
> figures.
> > > > > > panel.add(_label);
> > > > > > ....
> > > > > > This is the errors I got:
> > > > > > Unhandled event loop exception
> > > > > > Reason: Failed to execute runnable
> (java.lang.NullPointerException)
> > > > > > *** SWT nested exception
> > > > > > Reason: java.lang.NullPointerException
> > > > > >
> > > > > > Best Regards,
> > > > > > SL.
> > > > > >
> > > > > > "Lorenz Maierhofer" <lorenz.m@gmx.at> wrote in message
> > > > > > news:d381u0$8uk$1@news.eclipse.org...
> > > > > >
> > > > > >>Hi,
> > > > > >>see my posting above.
> > > > > >>Place the text into TextFlow and it gets wrapped.
> > > > > >>
> > > > > >>
> > > > > >>SL wrote:
> > > > > >>
> > > > > >>>Hi,
> > > > > >>>
> > > > > >>>I have a org.eclipse.draw2d.Label and would like to have the
text
> > > > > >>>wrapped around to next line if the box is not wide enough to
fit
> > the
> > > > > >>>string.
> > > > > >>>
> > > > > >>>Would someone please help and show me what do I need to do?
> > > > > >>>
> > > > > >>>Thanks
> > > > > >>>sl
> > > > > >>>
> > > > > >
> > > > > >
> > > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
|
|
|
|
|
|
|
|
|
Re: Wrap Text [message #178317 is a reply to message #177135] |
Tue, 19 April 2005 14:25   |
Eclipse User |
|
|
|
Originally posted by: jsk_lam.hotmail.com
Hi Pratik,
I have the following code snippet:
_textFlow = new TextFlow(node.getLabel());
ParagraphTextLayout layout = new ParagraphTextLayout(
_textFlow, ParagraphTextLayout.WORD_WRAP_SOFT);
_textFlow.setLayoutManager(layout);
_flowPage = new FlowPage();
_flowPage.add(_textFlow);
_flowPage.setHorizontalAligment(PositionConstants.CENTER );
// TODO: which one to set?
_textFlow.setFont(_fontLabel);
_flowPage.setFont(_fontLabel);
// Must set the font to use before calling getPreferredSize() or
exception will occur.
displayedTextPrefSize = _flowPage.getPreferredSize(); // width=???,
height=13
_nodePanel.add(_flowPage);
_flowPage.getPreferredSize() does not know how to return the number of lines
wrapped.
I really need to know how many lines wrapped to size the _nodePanel
accordingly.
The question I have is: How can I find the number of lines wrapped?
Also, I notice thta the WORD_WRAP_SOFT also break on the space if needed.
Best Regards
slam
"slam" <jsk_lam@hotmail.com> wrote in message
news:d3hbvr$j76$1@news.eclipse.org...
> Is there a way to get the size of the displayed text?
> Dimension flowPageSize_ = _flowPage.getSize(); // Always return
> (w=64, h=36) regardless of how many lines.
>
> This causes exception:
> Dimension flowPagePrefSize = _flowPage.getPreferredSize();
>
> I need to know the height of the _flowPage to size the container Panel
that
> contains the _flowPage.
>
>
> "Pratik Shah" <ppshah@us.ibm.com> wrote in message
> news:d3epln$4iu$1@news.eclipse.org...
> > Aah, that was an important piece of information you didn't mention
> earlier.
> >
> > Add these lines to your code:
> > ParagraphTextLayout layout = new ParagraphTextLayout(textFlow,
> > ParagraphTextLayout.WORD_WRAP_SOFT);
> > textFlow.setLayoutManager(layout);
> >
> > By default, TextFlow uses WORD_WRAP_HARD.
> >
> > "slam" <jsk_lam@hotmail.com> wrote in message
> > news:d3ep30$3nb$1@news.eclipse.org...
> > > It works only if the long string contains spaces in between, then the
> > string
> > > will wrap
> > > at the space boundary. If I have a long continuous string without
space
> > in
> > > between,
> > > then it will not wrap.
> > >
> > > "Randy Hudson" <none@us.ibm.com> wrote in message
> > > news:d3e4cl$3rq$1@news.eclipse.org...
> > > > It works for me:
> > > >
> > > > public static void main(String[] args) {
> > > > Display d = new Display();
> > > > Shell shell = new Shell(d);
> > > > shell.setLayout(new FillLayout());
> > > >
> > > > FigureCanvas canvas = new FigureCanvas(shell);
> > > > canvas.getViewport().setContentsTracksWidth(true);
> > > > Figure panel = new Figure();
> > > > panel.setLayoutManager(new ToolbarLayout());
> > > > TextFlow content = new TextFlow(System.getProperties().toString());
> > > > FlowPage fp = new FlowPage();
> > > > fp.add(content);
> > > > panel.add(fp);
> > > > panel.add(new Label("A label"));
> > > > canvas.setContents(panel);
> > > >
> > > >
> > > > shell.setText("draw2d");
> > > > shell.open();
> > > > while (!shell.isDisposed())
> > > > while (!d.readAndDispatch())
> > > > d.sleep();
> > > >
> > > > }
> > > >
> > > >
> > >
> > >
> >
> >
>
>
|
|
|
Re: Wrap Text [message #178355 is a reply to message #178317] |
Tue, 19 April 2005 17:38   |
Eclipse User |
|
|
|
"sl" <jsk_lam@hotmail.com> wrote in message
news:d43iul$rf5$1@news.eclipse.org...
> Hi Pratik,
>
> I have the following code snippet:
> _textFlow = new TextFlow(node.getLabel());
> ParagraphTextLayout layout = new ParagraphTextLayout(
> _textFlow, ParagraphTextLayout.WORD_WRAP_SOFT);
> _textFlow.setLayoutManager(layout);
> _flowPage = new FlowPage();
> _flowPage.add(_textFlow);
> _flowPage.setHorizontalAligment(PositionConstants.CENTER );
>
> // TODO: which one to set?
> _textFlow.setFont(_fontLabel);
> _flowPage.setFont(_fontLabel);
####
You should be able to figure this out by looking at Figure#getFont().
>
> // Must set the font to use before calling getPreferredSize() or
> exception will occur.
> displayedTextPrefSize = _flowPage.getPreferredSize(); //
width=???,
> height=13
####
If you debug this, you'll realize that invoking flowPage.getPreferredSize()
means invoking flowPage.getPreferredSize(-1, -1). What that means is that
you're asking the flowpage how big does it want to be if it had infinite
width and infinite height available. Since it has infinite width, it
doesn't need to wrap and hence it will return a size such that all text fits
on one line. If, however, you tell it how much width is available (height
would still be -1), it will return the appropriate size.
Your next question is going to be....how do you know how much width is
available? Use LayoutManagers and don't set the bounds of the figure
yourself. If you don't see why or how that'll fix your problem, set a
breakpoint in getPreferredSize(wHint, hHint) and walk through what's
happening and try to understand.
> _nodePanel.add(_flowPage);
>
> _flowPage.getPreferredSize() does not know how to return the number of
lines
> wrapped.
> I really need to know how many lines wrapped to size the _nodePanel
> accordingly.
>
> The question I have is: How can I find the number of lines wrapped?
>
> Also, I notice thta the WORD_WRAP_SOFT also break on the space if needed.
####
Yes, it wraps in a readable format if it can. This is the intended
behaviour.
>
> Best Regards
> slam
>
> "slam" <jsk_lam@hotmail.com> wrote in message
> news:d3hbvr$j76$1@news.eclipse.org...
> > Is there a way to get the size of the displayed text?
> > Dimension flowPageSize_ = _flowPage.getSize(); // Always return
> > (w=64, h=36) regardless of how many lines.
> >
> > This causes exception:
> > Dimension flowPagePrefSize = _flowPage.getPreferredSize();
> >
> > I need to know the height of the _flowPage to size the container Panel
> that
> > contains the _flowPage.
> >
> >
> > "Pratik Shah" <ppshah@us.ibm.com> wrote in message
> > news:d3epln$4iu$1@news.eclipse.org...
> > > Aah, that was an important piece of information you didn't mention
> > earlier.
> > >
> > > Add these lines to your code:
> > > ParagraphTextLayout layout = new ParagraphTextLayout(textFlow,
> > > ParagraphTextLayout.WORD_WRAP_SOFT);
> > > textFlow.setLayoutManager(layout);
> > >
> > > By default, TextFlow uses WORD_WRAP_HARD.
> > >
> > > "slam" <jsk_lam@hotmail.com> wrote in message
> > > news:d3ep30$3nb$1@news.eclipse.org...
> > > > It works only if the long string contains spaces in between, then
the
> > > string
> > > > will wrap
> > > > at the space boundary. If I have a long continuous string without
> space
> > > in
> > > > between,
> > > > then it will not wrap.
> > > >
> > > > "Randy Hudson" <none@us.ibm.com> wrote in message
> > > > news:d3e4cl$3rq$1@news.eclipse.org...
> > > > > It works for me:
> > > > >
> > > > > public static void main(String[] args) {
> > > > > Display d = new Display();
> > > > > Shell shell = new Shell(d);
> > > > > shell.setLayout(new FillLayout());
> > > > >
> > > > > FigureCanvas canvas = new FigureCanvas(shell);
> > > > > canvas.getViewport().setContentsTracksWidth(true);
> > > > > Figure panel = new Figure();
> > > > > panel.setLayoutManager(new ToolbarLayout());
> > > > > TextFlow content = new
TextFlow(System.getProperties().toString());
> > > > > FlowPage fp = new FlowPage();
> > > > > fp.add(content);
> > > > > panel.add(fp);
> > > > > panel.add(new Label("A label"));
> > > > > canvas.setContents(panel);
> > > > >
> > > > >
> > > > > shell.setText("draw2d");
> > > > > shell.open();
> > > > > while (!shell.isDisposed())
> > > > > while (!d.readAndDispatch())
> > > > > d.sleep();
> > > > >
> > > > > }
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
|
|
|
Re: Wrap Text [message #179028 is a reply to message #178317] |
Mon, 25 April 2005 10:04  |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
It's best to avoid calling setFont() unless you are changing from the
inherited one. Instead, you should add the figure to the lightweightsystem
it is going to showup in.
Can you back up a bit and tell us what you are trying to do. there is
probably a much easier way.
|
|
|
Powered by
FUDForum. Page generated in 0.04943 seconds