I want to create a view that users can zoom in and zoom out, so I planned to implement the view by using ScrolledComposite
:
ScrolledComposite sc = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
sc.setBounds(0, 0, 200, 200);
The problem is: when the size of content is smaller than the size of scrolled composite, it always appears in the top left corner of the scrolled composite, even I tried setBounds()
method of the control or setOrigin()
of scrolled composite. In the example below, the display area content of button
(100, 50) is smaller than the client area of sc
(200, 200), the button always is shown at the top left corner even I tried set up some position for it to display in the scrolled composite.
Button button = new Button(sc, SWT.PUSH);
button.setText("Button");
button.setBounds(50, 50, 100, 50);
sc.setContent(button);
sc.setOrigin(30, 30);
The result I get is
How can I fix this problem?