0

I'm having an issue with vertical scrolling, the scrolling bar appears on my shell but when I move the scroll bar the labels and the text inputs that located in the shell doesn't move. I deleted some code from the method that I think is irrelevant to the case, let me know if to post the full code. Thanks ahead.

public void initWidgets(String[] strings) throws IOException{
    GridData[] grids = new GridData[strings.length];
    for(int i=0;i<strings.length;i++){
        grids[i] = new GridData(SWT.FILL, SWT.FILL, true, true);            
    }
    Display display = new Display();
    final Shell shell = new Shell(display,SWT.SHELL_TRIM | SWT.V_SCROLL);
    shell.setSize(300, 500);
    GridLayout gridLayout = new GridLayout(2,false);
    shell.setLayout(gridLayout);
    shell.setText("Triggers Test");
    HashMap<String[], Text[][]> hm = new HashMap<>();
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.horizontalSpan = 2;
    Text[][] txt = new Text[strings.length][3];

    for(int i=0;i<strings.length;i++){
        Label label = new Label(shell, SWT.NONE); 
        label.setText(strings[i]+":");
        label.setLayoutData(gridData);
        FontData fontData = label.getFont().getFontData()[0];
        Font font = new Font(display, new FontData(fontData.getName(), fontData
                .getHeight(), SWT.BOLD | SWT.ITALIC));
        label.setFont(font);
        Label label2 = new Label(shell, SWT.NONE); 
        label2.setText("Yesterday's number:");
        Text t1 = new Text(shell, SWT.SINGLE | SWT.BORDER);
        t1.setLayoutData(grids[0]);
        Label label3 = new Label(shell, SWT.NONE); 
        label3.setText("From the day before:");
        Text t2 = new Text(shell, SWT.SINGLE | SWT.BORDER);
        t2.setLayoutData(grids[0]);
        Label label4 = new Label(shell, SWT.NONE);
        label4.setText("3 Months Average:");
        Text t3 = new Text(shell, SWT.SINGLE | SWT.BORDER);
        t3.setLayoutData(grids[0]);
    }

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Rea B.
  • 79
  • 8
  • 1
    `SWT.V_SCROLL` is not a supported style for `Shell`. You need to use something like `ScrolledComposite` inside the shell. – greg-449 Nov 07 '15 at 14:42
  • 1
    As a note: Please re-use the `Font` you're creating for all the labels that need it and don't forget to `dispose()` it when you don't need it anymore. – Baz Nov 07 '15 at 14:45
  • I actually also tried with ScrolledComposite but that didn't work also – Rea B. Nov 07 '15 at 14:59
  • 1
    https://www.eclipse.org/swt/snippets/ has lots of snippets, including some that will help you. If after using that resource, you are still struggling, please post additional questions. – Jonah Graham Nov 08 '15 at 09:24
  • 1
    Have a look at this snippet : http://stackoverflow.com/a/32863761/2691625. – Ardeshana Milan Nov 09 '15 at 08:48

0 Answers0