Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » ScrolledComposite Problems
ScrolledComposite Problems [message #448159] Tue, 04 January 2005 16:46
Benjamin Walstrum is currently offline Benjamin WalstrumFriend
Messages: 1
Registered: July 2009
Junior Member
I'm experiencing some strange problems related to the ScrolledComposite
custom widget, and am hoping that someone will be able to explain to me
either what is wrong with my code or whether this is a bug with the
widget (my first thought).

For background, I am creating a gameboard on a composite that is of a
fixed size, with the gameboard simply being an image which is drawn on
the background. Then I am going to use additional widgets drawn on top
of that. I am hoping to use a ScrolledComposite so that if they scale
up the board to a big size they can just scroll the board.

I have no problems getting the background to display. However,
additional widgets added only get drawn if the board is large enough to
NOT scroll inside of the ScrolledComposite (once they have been drawn
once they seem to be OK though). Resizing the control until the
underlying composite can fit in at least one dimension will then cause
the control to appear.

I'm adding example source that shows this effect. I have tested it in
3.0, 3.1 M3, and 3.1 M4.

I can't think of any good reason why the controls shouldn't be drawn in
all circumstances. Any direction would be greatly appreciated.

Ben Walstrum

----

import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class ScrolledCompositeTest {

private static class ColorComposite extends Composite {

private final int width;
private final int height;
private final int color;

public ColorComposite(final Composite parent, final int width,
final int height, final int color) {
super(parent, SWT.NONE);
this.width = width;
this.height = height;
this.color = color;

addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
e.gc.setBackground(getDisplay().getSystemColor(color));
e.gc.fillRectangle(0, 0, width, height);
}
});
}

public Point computeSize(int wHint, int hHint) {
int w = wHint == SWT.DEFAULT ? width : wHint;
int h = hHint == SWT.DEFAULT ? height : hHint;
return new Point(w, h);
}
}

public static void main (String [] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());

ScrolledComposite sc1 = new ScrolledComposite(shell,
SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
sc1.setExpandHorizontal(true);
sc1.setExpandVertical(true);

ColorComposite cc1 = new ColorComposite(sc1, 100, 100,
SWT.COLOR_GREEN);
cc1.setLayout(new GridLayout());
sc1.setContent(cc1);
sc1.setMinSize(cc1.computeSize(SWT.DEFAULT, SWT.DEFAULT));

Button b1 = new Button(cc1, SWT.PUSH);
b1.setText("Button");

ScrolledComposite sc2 = new ScrolledComposite(shell,
SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
sc2.setExpandHorizontal(true);
sc2.setExpandVertical(true);

ColorComposite cc2 = new ColorComposite(sc2, 300, 300,
SWT.COLOR_RED);
cc2.setLayout(new GridLayout());
sc2.setContent(cc2);
sc2.setMinSize(cc2.computeSize(SWT.DEFAULT, SWT.DEFAULT));

Button b2 = new Button(cc2, SWT.PUSH);
b2.setText("Button");

shell.setSize(400, 200);
shell.open();

while (!shell.isDisposed ()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
Previous Topic:Menus on MAC problem. URGENT!
Next Topic:modify listener for OleClientSite
Goto Forum:
  


Current Time: Thu Apr 25 07:28:37 GMT 2024

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

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

Back to the top