Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to scroll in this composite with Page-Up/Down?(I have to make a dialog accessible, but I cannot scroll with Page-Up/Down within this composite)
How to scroll in this composite with Page-Up/Down? [message #760150] Thu, 01 December 2011 13:43 Go to next message
Simon Mising name is currently offline Simon Mising nameFriend
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));
	}

}
Re: How to scroll in this composite with Page-Up/Down? [message #760846 is a reply to message #760150] Mon, 05 December 2011 12:37 Go to previous message
Simon Mising name is currently offline Simon Mising nameFriend
Messages: 12
Registered: December 2011
Junior Member
This thread can be closed.
Solution:

scrolledComposite.setShowFocusedControl(true);
Previous Topic:masked value for swt text field based on indicator
Next Topic:Converting a BufferedImage which uses ComponentColorModel
Goto Forum:
  


Current Time: Fri Nov 28 01:55:38 GMT 2014

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

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