Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] What happened to the scroll bars ?

Hello

First, thanks to Veronika for her response to my post on the thread "Is
Layout required for Event handling?", appologies for the long delay in
replying but I have had a prolonged unexpected absense from the project.
The changes to the code have helped my understanding of SWT.

However I am trying to replicate the effect of the Excel Split
pane/Freeze pane combination in which the left hand area is narrower
than the right. I therefore changed the FillLayout to RowLayout, set the
rowLayout.wrap to false and the two tables were displayed as required
but the scroll bars have disappeared. I also tried the GridLayout but
this had the same effect.

Why should these controls behave differently in these layouts? How do I
get the scrollbars back in the other layouts?

Here is the code

package com.wcg.framework.workflow.ui.designer;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

/**
 * Title:        Matrix View
 * Description:
 * Copyright:    Copyright (c) 2002
 * Company:
 * @author
 * @version 1.0
 */

public class MatrixView {

  public MatrixView() {
  }

  public static void main (String [] args) {
    Display display = new Display ();
    Shell shell = new Shell (display);
//    shell.setLayout(new FillLayout());
  
    RowLayout rowLayout = new RowLayout();
    rowLayout.wrap = false;
    shell.setLayout(rowLayout);
    
//    GridLayout gridLayout = new GridLayout();
//    gridLayout.numColumns = 2;
//    gridLayout.marginWidth = 1;
//    shell.setLayout(gridLayout);
    
    final ScrolledComposite sc1 = new ScrolledComposite (shell,
SWT.H_SCROLL 
| SWT.V_SCROLL);
    final ScrolledComposite sc2 = new ScrolledComposite (shell,
SWT.H_SCROLL 
| SWT.V_SCROLL);

    Table table1 = new Table(sc1,SWT.SINGLE);
    table1.setHeaderVisible(false);
    table1.setLinesVisible(true);

    TableColumn col1  = new TableColumn(table1,SWT.LEFT);
    col1.setWidth(200);
    TableColumn col2  = new TableColumn(table1,SWT.LEFT);
    col2.setWidth(60);

    for (int i = 0; i < 60; i++) {
      TableItem item1 = new TableItem(table1,0);
      item1.setText(new String[]{"Line " + i,"b"});
    }

    Table table2 = new Table(sc2,SWT.SINGLE);
    table2.setHeaderVisible(false);
    table2.setLinesVisible(true);

    for (int i = 0; i < 10; i++) {
      TableColumn col21  = new TableColumn(table2,SWT.LEFT);
      col21.setWidth(80);
    }

    for (int i = 0; i < 60; i++) {
      TableItem item1 = new TableItem(table2,0);
      item1.setText(new String[]{"Line "+i,"c"});
    }

    sc1.setContent(table1);
    table1.pack();

    sc2.setContent(table2);
    table2.pack();

    final ScrollBar vBar1 = sc1.getVerticalBar ();
    final ScrollBar vBar2 = sc2.getVerticalBar ();
    final ScrollBar hBar1 = sc1.getHorizontalBar ();
    final ScrollBar hBar2 = sc2.getHorizontalBar ();

    SelectionListener listener1 = new SelectionAdapter () {
      public void widgetSelected (SelectionEvent e) {
          int x =  hBar1.getSelection() * (hBar2.getMaximum() - 
hBar2.getThumb()) / Math.max(1, hBar1.getMaximum() - hBar1.getThumb());
          int y =  vBar1.getSelection() * (vBar2.getMaximum() - 
vBar2.getThumb()) / Math.max(1, vBar1.getMaximum() - vBar1.getThumb());
          sc2.setOrigin (x, y);
      }
    };
    SelectionListener listener2 = new SelectionAdapter () {
      public void widgetSelected (SelectionEvent e) {
          int x =  hBar2.getSelection() * (hBar1.getMaximum() - 
hBar1.getThumb()) / Math.max(1, hBar2.getMaximum() - hBar2.getThumb());
          int y =  vBar2.getSelection() * (vBar1.getMaximum() - 
vBar1.getThumb()) / Math.max(1, vBar2.getMaximum() - vBar2.getThumb());
          sc1.setOrigin (x, y);
      }
    };
    vBar1.addSelectionListener (listener1);
    hBar1.addSelectionListener (listener1);
    vBar2.addSelectionListener (listener2);
    hBar2.addSelectionListener (listener2);
    System.out.println("Show");

    shell.setSize (500, 500);
    shell.open ();
    while (!shell.isDisposed ()) {
      if (!display.readAndDispatch ()) display.sleep ();
    }
    display.dispose ();
  } 



}




Back to the top