Preferred size - please help [message #152953] |
Wed, 06 October 2004 00:56 |
Eclipse User |
|
|
|
Originally posted by: eclipse-news.telus.net
Hi,
I would like to know how to get the preferred size of the Figure which
contains other children (and is the contents of the FigureCanvas) before
it's layed out on the screen. Figure.getClientArea(), and getBounds()
return only (64,36) as well as FigureCanvas.computeSize(-1, -1) - (60,32).
The actual shell size is much bigger.
Thank you,
Ihor
|
|
|
|
Re: Preferred size - please help [message #153177 is a reply to message #153125] |
Wed, 06 October 2004 21:29 |
Eclipse User |
|
|
|
Originally posted by: eclipse-news.telus.net
Here is my code:
import org.eclipse.draw2d.*;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class Test {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setSize(1100, 700);
TestView view = new TestView(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private static class TestView {
TestView(Composite parent) {
createView(parent);
}
private void createView(Composite parent) {
FigureCanvas fc = new FigureCanvas(parent);
fc.setContents(buildContents());
fc.setLayoutData(new GridData(GridData.FILL_BOTH));
fc.getViewport().setContentsTracksHeight(true);
fc.getViewport().setContentsTracksWidth(true);
}
public Figure buildContents() {
Figure contents = new Panel();
contents.setBackgroundColor(ColorConstants.white);
contents.setLayoutManager(new XYLayout());
contents.setBorder(new LineBorder());
RectangleFigure bar = new RectangleFigure();
Rectangle bounds = new Rectangle(10, 10, 100, 100);
//How can I dynamically fill the whole available canvas area
with this RectangleFigure?
bar.setBounds(bounds);
contents.add(bar, bounds);
System.out.println("contents clientArea: " +
contents.getClientArea());
System.out.println("contents preferredSize: " +
contents.getPreferredSize());
return contents;
}
}
}
Is there a way to find the canvas size before I start putting Figures onto
it?
Thanks Patrik,
Ihor
Pratik Shah wrote:
> Can you post some code showing the problem? What is the Figure's layout?
> "Ihor Strutynskyj" <eclipse-news@telus.net> wrote in message
> news:cjvfrj$gjb$1@eclipse.org...
> > Hi,
> > I would like to know how to get the preferred size of the Figure which
> > contains other children (and is the contents of the FigureCanvas) before
> > it's layed out on the screen. Figure.getClientArea(), and getBounds()
> > return only (64,36) as well as FigureCanvas.computeSize(-1, -1) - (60,32).
> > The actual shell size is much bigger.
> >
> > Thank you,
> > Ihor
> >
|
|
|
Re: Preferred size - please help [message #153185 is a reply to message #153177] |
Wed, 06 October 2004 21:59 |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
You're asking what the size of the shell is going to be? Since that
determine the size of everything else. You can invoke layout on the Shell
before you show it.
"Ihor Strutynskyj" <eclipse-news@telus.net> wrote in message
news:ck1o4l$og9$1@eclipse.org...
> Here is my code:
>
> import org.eclipse.draw2d.*;
> import org.eclipse.draw2d.geometry.Rectangle;
> import org.eclipse.swt.layout.*;
> import org.eclipse.swt.widgets.*;
>
> public class Test {
> public static void main(String[] args) {
> Display display = new Display();
> Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());
> shell.setSize(1100, 700);
> TestView view = new TestView(shell);
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
>
> private static class TestView {
> TestView(Composite parent) {
> createView(parent);
> }
>
> private void createView(Composite parent) {
> FigureCanvas fc = new FigureCanvas(parent);
> fc.setContents(buildContents());
> fc.setLayoutData(new GridData(GridData.FILL_BOTH));
> fc.getViewport().setContentsTracksHeight(true);
> fc.getViewport().setContentsTracksWidth(true);
> }
>
> public Figure buildContents() {
> Figure contents = new Panel();
> contents.setBackgroundColor(ColorConstants.white);
> contents.setLayoutManager(new XYLayout());
> contents.setBorder(new LineBorder());
>
> RectangleFigure bar = new RectangleFigure();
> Rectangle bounds = new Rectangle(10, 10, 100, 100);
>
> //How can I dynamically fill the whole available canvas area
> with this RectangleFigure?
>
> bar.setBounds(bounds);
> contents.add(bar, bounds);
> System.out.println("contents clientArea: " +
> contents.getClientArea());
> System.out.println("contents preferredSize: " +
> contents.getPreferredSize());
> return contents;
> }
> }
> }
>
>
> Is there a way to find the canvas size before I start putting Figures onto
> it?
>
>
> Thanks Patrik,
> Ihor
>
>
> Pratik Shah wrote:
>
> > Can you post some code showing the problem? What is the Figure's
layout?
>
> > "Ihor Strutynskyj" <eclipse-news@telus.net> wrote in message
> > news:cjvfrj$gjb$1@eclipse.org...
> > > Hi,
> > > I would like to know how to get the preferred size of the Figure which
> > > contains other children (and is the contents of the FigureCanvas)
before
> > > it's layed out on the screen. Figure.getClientArea(), and getBounds()
> > > return only (64,36) as well as FigureCanvas.computeSize(-1, -1) -
(60,32).
> > > The actual shell size is much bigger.
> > >
> > > Thank you,
> > > Ihor
> > >
>
>
|
|
|
Re: Preferred size - please help [message #153299 is a reply to message #153177] |
Thu, 07 October 2004 16:03 |
Pratik Shah Messages: 1077 Registered: July 2009 |
Senior Member |
|
|
> //How can I dynamically fill the whole available canvas area
> with this RectangleFigure?
Change contents' layout to StackLayout (You might not even need the outer
panel; the RectangleFigure can be the contents).
"Ihor Strutynskyj" <eclipse-news@telus.net> wrote in message
news:ck1o4l$og9$1@eclipse.org...
> Here is my code:
>
> import org.eclipse.draw2d.*;
> import org.eclipse.draw2d.geometry.Rectangle;
> import org.eclipse.swt.layout.*;
> import org.eclipse.swt.widgets.*;
>
> public class Test {
> public static void main(String[] args) {
> Display display = new Display();
> Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());
> shell.setSize(1100, 700);
> TestView view = new TestView(shell);
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
>
> private static class TestView {
> TestView(Composite parent) {
> createView(parent);
> }
>
> private void createView(Composite parent) {
> FigureCanvas fc = new FigureCanvas(parent);
> fc.setContents(buildContents());
> fc.setLayoutData(new GridData(GridData.FILL_BOTH));
> fc.getViewport().setContentsTracksHeight(true);
> fc.getViewport().setContentsTracksWidth(true);
> }
>
> public Figure buildContents() {
> Figure contents = new Panel();
> contents.setBackgroundColor(ColorConstants.white);
> contents.setLayoutManager(new XYLayout());
> contents.setBorder(new LineBorder());
>
> RectangleFigure bar = new RectangleFigure();
> Rectangle bounds = new Rectangle(10, 10, 100, 100);
>
> //How can I dynamically fill the whole available canvas area
> with this RectangleFigure?
>
> bar.setBounds(bounds);
> contents.add(bar, bounds);
> System.out.println("contents clientArea: " +
> contents.getClientArea());
> System.out.println("contents preferredSize: " +
> contents.getPreferredSize());
> return contents;
> }
> }
> }
>
>
> Is there a way to find the canvas size before I start putting Figures onto
> it?
>
>
> Thanks Patrik,
> Ihor
>
>
> Pratik Shah wrote:
>
> > Can you post some code showing the problem? What is the Figure's
layout?
>
> > "Ihor Strutynskyj" <eclipse-news@telus.net> wrote in message
> > news:cjvfrj$gjb$1@eclipse.org...
> > > Hi,
> > > I would like to know how to get the preferred size of the Figure which
> > > contains other children (and is the contents of the FigureCanvas)
before
> > > it's layed out on the screen. Figure.getClientArea(), and getBounds()
> > > return only (64,36) as well as FigureCanvas.computeSize(-1, -1) -
(60,32).
> > > The actual shell size is much bigger.
> > >
> > > Thank you,
> > > Ihor
> > >
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03206 seconds