How to scroll in this composite with Page-Up/Down? [message #760150] |
Thu, 01 December 2011 13:43 |
Simon Mising name Messages: 12 Registered: December 2011 |
Junior Member |
|
|
Hi,
I have a little problem:
There exists a composite which contains a Textfield and a Button. This composite is wrapped with a scrolled-composite.
If the focus is on either the Textfield or the Button, it is not possible to scroll the parent composite with the Page Up/Down keys.
My question is now, how to obtain my goal, to enable scrolling within this composite by using Page Up/Down?
Is there a possibility to use a KeyListener or something else, to enable scrolling?
Thanks for you help!
Here my little sample class:
public class Test {
protected Shell shell;
private Text txtLdfjslkdflksjflks;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
Test window = new Test();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.setSize(300, 300);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(300, 300);
shell.setText("SWT Application");
shell.setLayout(new FillLayout());
shell.layout();
ScrolledComposite sc = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
sc.setLayout(new GridLayout(1, false));
Composite comp = new Composite(sc, SWT.NONE);
sc.setContent(comp);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
comp.setLayout(new GridLayout(1, true));
txtLdfjslkdflksjflks = new Text(comp, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP);
txtLdfjslkdflksjflks.setText("ldfjsl\nkd\nflksjflkss\r\ndf\r\nsdf\r\n\r\nsdf\r\ns\r\ndf\r\nsad\r\nf\r\nsd\r\nfsdf\r\n");
Button b = new Button(comp, SWT.PUSH);
b.setText("Button");
sc.setMinSize(comp.getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.07380 seconds