|
|
|
Re: getPreferredSize() not returning proper size until after invalidating layout [message #197459 is a reply to message #197083] |
Mon, 03 October 2005 17:42 |
Eclipse User |
|
|
|
Originally posted by: none.unknown.com
The problem is that the figure hierarchy hasn't had a chance to validate
yet. When it's in the invalid state, there's no guarantee that the results
are correct. So, you can either force the validation to happen right away,
as follows:
canvas.getLightweightSystem().getRootFigure().validate();
OR
canvas.getLightweightSystem().getUpdateManager().performUpda te();
Or you can just wait for the update manager to validate the figures
asynchronously on the Display thread and just get your preferred size
afterwards. As follows:
display.asyncExec(new Runnable() {
public void run() {
System.out.println(figure.getPreferredSize());
}
});
Since you're queuing your code asynchronously on the display thread as well
in the above example, you're guaranteed that the UpdateManager would've had
a chance to run before your code is executed.
"Brad Reynolds" <bradleyjames@gmail.com> wrote in message
news:433BEEA5.7060504@gmail.com...
> Any ideas? I'm just wanting to make sure that I'm not doing something I
> shouldn't be. If there's a better way to do this I'd appreciate the
> input. Thanks.
>
> Brad Reynolds wrote:
> > When I run the following snippet the preferred size for the label will
> > be the same even after multiple sets of the text until I invalidate the
> > layout. It renders fine but when calling getPreferredSize() I'm not
> > being returned the proper size. I have the need to set the text on a
> > Label (perhaps a few times) and then afterward to retrieve an accurate
> > preferred size. Is this the correct way to be doing this? Is there a
> > better way? From what I can tell the issue is because in invalidate()
> > of Figure it checks to see if the figure is valid, if not it won't
> > invalidate the layout. After setting the text the Label becomes invalid
> > and thus won't invalidate the figure again and won't update the layout
> > of my parent figure and therefore won't return the correct size.
> >
> > public class ValidTest {
> > public static void main(String[] args) {
> > Display display = new Display();
> > Shell shell = new Shell(display);
> > shell.setLayout(new FillLayout());
> >
> > FigureCanvas canvas = new FigureCanvas(shell);
> > Figure content = new Figure();
> > content.setLayoutManager(new FlowLayout());
> > canvas.setContents(content);
> >
> > Figure figure = new Figure();
> > content.add(figure);
> >
> > StackLayout layout = new StackLayout();
> > figure.setLayoutManager(layout);
> >
> > Label label = new Label("text"); //$NON-NLS-1$
> > figure.add(label);
> >
> > System.out.println(figure.getPreferredSize());
> >
> > label.setText("text text"); //$NON-NLS-1$
> >
> > //Uncomment to retrieve the correct preferred size.
> > // layout.invalidate();
> >
> > System.out.println(figure.getPreferredSize());
> >
> > shell.open();
> > while (!shell.isDisposed()) {
> > if (!display.readAndDispatch())
> > display.sleep();
> > }
> >
> > display.dispose();
> > }
> > }
> >
> >
> > Thanks,
> > Brad
|
|
|
Re: getPreferredSize() not returning proper size until after invalidating layout [message #197594 is a reply to message #196879] |
Tue, 04 October 2005 13:56 |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
This sounds like a bug. Please file a bugzilla.
"Brad Reynolds" <bradleyjames@gmail.com> wrote in message
news:dhc2vf$fgh$1@news.eclipse.org...
> When I run the following snippet the preferred size for the label will be
> the same even after multiple sets of the text until I invalidate the
> layout. It renders fine but when calling getPreferredSize() I'm not being
> returned the proper size. I have the need to set the text on a Label
> (perhaps a few times) and then afterward to retrieve an accurate preferred
> size. Is this the correct way to be doing this? Is there a better way?
> From what I can tell the issue is because in invalidate() of Figure it
> checks to see if the figure is valid, if not it won't invalidate the
> layout. After setting the text the Label becomes invalid and thus won't
> invalidate the figure again and won't update the layout of my parent
> figure and therefore won't return the correct size.
>
> public class ValidTest {
> public static void main(String[] args) {
> Display display = new Display();
> Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());
>
> FigureCanvas canvas = new FigureCanvas(shell);
> Figure content = new Figure();
> content.setLayoutManager(new FlowLayout());
> canvas.setContents(content);
>
> Figure figure = new Figure();
> content.add(figure);
>
> StackLayout layout = new StackLayout();
> figure.setLayoutManager(layout);
> Label label = new Label("text"); //$NON-NLS-1$
> figure.add(label);
>
> System.out.println(figure.getPreferredSize());
>
> label.setText("text text"); //$NON-NLS-1$
>
> //Uncomment to retrieve the correct preferred size.
> // layout.invalidate();
>
> System.out.println(figure.getPreferredSize());
>
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
>
> display.dispose();
> }
> }
>
>
> Thanks,
> Brad
|
|
|
Powered by
FUDForum. Page generated in 0.04259 seconds