Client Area of a scrolled composite [message #446866] |
Fri, 03 December 2004 15:05  |
Eclipse User |
|
|
|
<br><font size=1 face="sans-serif">I am creating a view which contains two columns, the first column has a question in it and the second either a text, button(checkbox) or combo. As the questions can be 1, 2 or 3 lines long I am drawing the components in response to a selection changed event.</font>
<br>
<br><font size=1 face="sans-serif">I have the composite from the view into which I have placed a scrolled composite and into that a composite in which I paint the components.</font>
<br>
<br><font size=1 face="sans-serif">I use the get client area of the scroll are to decide how wide to make my composite, set its size and it appears.</font>
<br>
<br><font size=1 face="sans-serif">The problem I have is when my composite gets too long the scrolled composite turns on the sroll bars (as it should) but these cover up the edge of my composite as the getClientArea returns the size without the scrollbar present. </font>
<br>
<br><font size=1 face="sans-serif">How can I detect the scrollbar has appeared so I can redraw the componets a bit narrower.</font>
<br>
<br><font size=1 face="sans-serif">As a workaround at the moment I have got the sroll bar to always appear so the client area always returns the correct size.</font>
<br>
<br><font size=1 face="sans-serif">My first plug-in so bear with me if this is obvoius</font>
|
|
|
Re: Client Area of a scrolled composite [message #446868 is a reply to message #446866] |
Fri, 03 December 2004 16:38  |
Eclipse User |
|
|
|
ScrolledComposite.getClientArea does not include the scrollbars.
Here is a simple example that demonstrates this. Resize the shell and you
will always see the red rectangle, even when the scrollbars are present.
public static void main (String [] args) {
Display display = new Display ();
final Color red = display.getSystemColor(SWT.COLOR_RED);
Shell shell = new Shell (display);
shell.setLayout(new FillLayout());
final ScrolledComposite sc = new ScrolledComposite(shell, SWT.BORDER
| SWT.H_SCROLL | SWT.V_SCROLL);
final Composite c = new Composite(sc, SWT.NONE);
c.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
Rectangle r = sc.getClientArea();
Point origin = sc.getOrigin();
e.gc.setForeground(red);
e.gc.drawRectangle(origin.x+ 3, origin.y + 3,
r.width - 6, r.height - 6);
}
});
c.addControlListener(new ControlAdapter() {
public void controlMoved(ControlEvent e) {
c.redraw();
}
});
sc.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
c.redraw();
}
});
sc.setContent(c);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setMinSize(300, 300);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
<Phill_Perryman@Mitel.COM> wrote in message
news:coqgva$nmn$1@www.eclipse.org...
I am creating a view which contains two columns, the first column has a
question in it and the second either a text, button(checkbox) or combo. As
the questions can be 1, 2 or 3 lines long I am drawing the components in
response to a selection changed event.
I have the composite from the view into which I have placed a scrolled
composite and into that a composite in which I paint the components.
I use the get client area of the scroll are to decide how wide to make my
composite, set its size and it appears.
The problem I have is when my composite gets too long the scrolled composite
turns on the sroll bars (as it should) but these cover up the edge of my
composite as the getClientArea returns the size without the scrollbar
present.
How can I detect the scrollbar has appeared so I can redraw the componets a
bit narrower.
As a workaround at the moment I have got the sroll bar to always appear so
the client area always returns the correct size.
My first plug-in so bear with me if this is obvoius
|
|
|
Powered by
FUDForum. Page generated in 0.03892 seconds