Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Why does SelectionListener fail to fire?
Why does SelectionListener fail to fire? [message #459751] |
Mon, 15 August 2005 14:19 |
Eclipse User |
|
|
|
Originally posted by: mike.swt.demon.co.uk
Hello
I am implemention a 4 table display and am using the example in the snippets
to synchronise two tables, however when I add a SelectionListener to the
ScrolledComposite, it fails to fire when I move the scroll bar.
The code is shown below, it defines 4 tables topLeft, topRight, bottomLeft
and bottomRight within a FormLayout.
(As a secondarty question, why does bottomLeft fail to extend to the bottom
of the Shell despite expandVertical being set to true ?)
Your help would be most appreciated
Thanks
Mike
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
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;
public class TableScrollTest {
TableViewer columnViewer;
/**
* @param args
*/
public static void main(String[] args) {
TableScrollTest tableScrollTest = new TableScrollTest();
tableScrollTest.run();
}
public void run() {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setSize (900, 400);
FormLayout formLayout = new FormLayout();
shell.setLayout(formLayout);
// Top left
final Table topLeft = new Table(shell,SWT.SINGLE | SWT.FULL_SELECTION);
topLeft.setHeaderVisible(true);
topLeft.setLinesVisible(true);
FormData topLeftFormData = new FormData();
topLeftFormData.width = 244;
topLeft.setLayoutData(topLeftFormData);
TableColumn tlColumn1 = new TableColumn(topLeft,SWT.LEFT);
tlColumn1.setWidth(200);
TableColumn tlColumn2 = new TableColumn(topLeft,SWT.LEFT);
tlColumn2.setWidth(60);
for (int i=0; i<2; i++) {
new TableItem (topLeft, SWT.NONE);
}
topLeft.pack();
// Top right
final ScrolledComposite trScroller = new ScrolledComposite (shell,
SWT.H_SCROLL );
FormLayout trFormLayout = new FormLayout();
trScroller.setLayout(trFormLayout);
trScroller.setExpandHorizontal(true);
final FormData trScrollerFormData = new FormData();
trScrollerFormData.left = new FormAttachment(topLeft, 5);
trScrollerFormData.top = new FormAttachment(0);
trScrollerFormData.width = shell.getClientArea().width -
topLeft.getSize().x - 5;
trScroller.setLayoutData(trScrollerFormData);
final Table topRight = new Table(trScroller,SWT.SINGLE|
SWT.FULL_SELECTION | SWT.HIDE_SELECTION );
topRight.setHeaderVisible(true);
topRight.setLinesVisible(false);
for (int i = 0; i < 10; i++) {
TableColumn tableColumn = new TableColumn(topRight,SWT.CENTER);
tableColumn.setWidth(80);
}
for (int i=0; i<2; i++) {
new TableItem (topRight, SWT.NONE);
}
topRight.pack();
final FormData trFormData = new FormData();
trFormData.left = new FormAttachment(0, 0);
trFormData.top = new FormAttachment(0);
trFormData.width = shell.getClientArea().width - topLeft.getSize().x -
5;
topRight.setLayoutData(trFormData);
trScroller.setContent(topRight);
// Bottom Left
final ScrolledComposite blScroller = new ScrolledComposite (shell,
SWT.V_SCROLL);
blScroller.setExpandVertical(true);
final FormData blScrollerFormData = new FormData();
blScrollerFormData.left = new FormAttachment(0, 5);
blScrollerFormData.top = new FormAttachment(topLeft, 5);
blScrollerFormData.width = 244;
blScroller.setLayoutData(blScrollerFormData);
final Table bottomLeft = new Table(blScroller,SWT.SINGLE |
SWT.FULL_SELECTION);
bottomLeft.setHeaderVisible(true);
bottomLeft.setLinesVisible(true);
TableColumn blColumn1 = new TableColumn(bottomLeft,SWT.LEFT);
blColumn1.setWidth(200);
TableColumn blColumn2 = new TableColumn(bottomLeft,SWT.LEFT);
blColumn2.setWidth(60);
for (int i=0; i<12; i++) {
TableItem item = new TableItem (bottomLeft, SWT.NONE);
item.setText(new String[] {"Row " , String.valueOf(i)});
}
bottomLeft.pack();
FormData blFormData = new FormData();
blFormData.width = 244;
blFormData.left = new FormAttachment(0, 0);
blFormData.top = new FormAttachment(0);
bottomLeft.setLayoutData(blFormData);
blScroller.setContent(bottomLeft);
// Bottom right
final ScrolledComposite brScroller = new ScrolledComposite (shell,
SWT.NONE);
brScroller.setExpandHorizontal(true);
brScroller.setExpandVertical(true);
final Table bottomRight = new Table(brScroller,SWT.SINGLE|
SWT.FULL_SELECTION | SWT.HIDE_SELECTION );
bottomRight.setHeaderVisible(false);
bottomRight.setLinesVisible(true);
for (int i = 0; i < 10; i++) {
TableColumn tableColumn = new TableColumn(bottomRight,SWT.CENTER);
tableColumn.setWidth(80);
}
for (int i=0; i<12; i++) {
TableItem item = new TableItem (bottomRight, SWT.NONE);
String [] line = new String[10];
for (int j = 0; j < line.length; j++) {
line[j] = String.valueOf(i*10+j);
}
item.setText(line);
}
bottomRight.pack();
final FormData brFormData = new FormData();
brFormData.left = new FormAttachment(blScroller, 5);
brFormData.top = new FormAttachment(trScroller, 0);
brFormData.width = shell.getClientArea().width - topLeft.getSize().x -
5;
brScroller.setLayoutData(brFormData);
brScroller.setContent(bottomRight);
shell.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent event) {
Shell shell = (Shell)event.getSource();
Rectangle rect = shell.getClientArea();
trFormData.width = rect.width - topLeft.getSize().x - 5;
trScrollerFormData.width = rect.width - topLeft.getSize().x - 5;
brFormData.width = rect.width - topLeft.getSize().x - 5;
brFormData.height = rect.height - topRight.getSize().y - 5;
shell.layout();
}
});
final ScrollBar trScrollBar = trScroller.getHorizontalBar();
trScrollBar.addSelectionListener( new SelectionAdapter () {
public void widgetSelected (SelectionEvent e) {
// >>>> This does not fire <<<<
System.out.println("trScrollBar " + trScrollBar.getSelection () + "
" + trScrollBar.getSelection ());
brScroller.setOrigin(trScrollBar.getSelection(), 0);
}
});
final ScrollBar brScrollBar = trScroller.getHorizontalBar();
brScrollBar.addSelectionListener( new SelectionAdapter () {
public void widgetSelected (SelectionEvent e) {
// >>>> This does not fire <<<<
System.out.println("brScrollBar " + brScrollBar.getSelection () + "
" + brScrollBar.getSelection ());
brScroller.setOrigin(trScrollBar.getSelection(), 0);
}
});
shell.open ();
Rectangle rect = shell.getClientArea();
trFormData.width = rect.width - topLeft.getSize().x - 5;
trScrollerFormData.width = rect.width - topLeft.getSize().x - 5;
brFormData.width = rect.width - topLeft.getSize().x - 5;
brFormData.height = rect.height - topRight.getSize().y - 5;
shell.layout();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
|
|
|
Re: Why does SelectionListener fail to fire? [message #459795 is a reply to message #459751] |
Wed, 17 August 2005 08:48 |
Eclipse User |
|
|
|
Originally posted by: mike.swt.demon.co.uk
Hello
I am reposting this in the hope that someone missed it before who can help,
this is the final piece of the jigsaw and all attempts so far have failed.
In a separate test, the listener is fired but I can't see why this example
does not
Thanks
Mike
> I am implementing a 4 table display and am using the example in the
> snippets to synchronise two tables, however when I add a SelectionListener
> to the ScrolledComposite, it fails to fire when I move the scroll bar.
>
> The code is shown below, it defines 4 tables topLeft, topRight, bottomLeft
> and bottomRight within a FormLayout.
>
> (As a secondary question, why does bottomLeft fail to extend to the bottom
> of the Shell despite expandVertical being set to true ?)
>
> Your help would be most appreciated
>
> Thanks
> Mike
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.custom.ScrolledComposite;
> import org.eclipse.swt.events.ControlAdapter;
> import org.eclipse.swt.events.ControlEvent;
> import org.eclipse.swt.events.SelectionAdapter;
> import org.eclipse.swt.events.SelectionEvent;
> import org.eclipse.swt.graphics.Rectangle;
> import org.eclipse.swt.layout.FormAttachment;
> import org.eclipse.swt.layout.FormData;
> import org.eclipse.swt.layout.FormLayout;
> 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;
>
> public class TableScrollTest {
> TableViewer columnViewer;
> /**
> * @param args
> */
> public static void main(String[] args) {
> TableScrollTest tableScrollTest = new TableScrollTest();
> tableScrollTest.run();
> }
>
> public void run() {
>
> Display display = new Display ();
>
> Shell shell = new Shell (display);
> shell.setSize (900, 400);
>
> FormLayout formLayout = new FormLayout();
> shell.setLayout(formLayout);
>
> // Top left
>
> final Table topLeft = new Table(shell,SWT.SINGLE | SWT.FULL_SELECTION);
> topLeft.setHeaderVisible(true);
> topLeft.setLinesVisible(true);
> FormData topLeftFormData = new FormData();
> topLeftFormData.width = 244;
> topLeft.setLayoutData(topLeftFormData);
> TableColumn tlColumn1 = new TableColumn(topLeft,SWT.LEFT);
> tlColumn1.setWidth(200);
> TableColumn tlColumn2 = new TableColumn(topLeft,SWT.LEFT);
> tlColumn2.setWidth(60);
> for (int i=0; i<2; i++) {
> new TableItem (topLeft, SWT.NONE);
> }
> topLeft.pack();
> // Top right
>
> final ScrolledComposite trScroller = new ScrolledComposite (shell,
> SWT.H_SCROLL );
> FormLayout trFormLayout = new FormLayout();
> trScroller.setLayout(trFormLayout);
> trScroller.setExpandHorizontal(true);
> final FormData trScrollerFormData = new FormData();
> trScrollerFormData.left = new FormAttachment(topLeft, 5);
> trScrollerFormData.top = new FormAttachment(0);
> trScrollerFormData.width = shell.getClientArea().width -
> topLeft.getSize().x - 5;
> trScroller.setLayoutData(trScrollerFormData);
> final Table topRight = new Table(trScroller,SWT.SINGLE|
> SWT.FULL_SELECTION | SWT.HIDE_SELECTION );
> topRight.setHeaderVisible(true);
> topRight.setLinesVisible(false);
> for (int i = 0; i < 10; i++) {
> TableColumn tableColumn = new TableColumn(topRight,SWT.CENTER);
> tableColumn.setWidth(80);
> }
>
> for (int i=0; i<2; i++) {
> new TableItem (topRight, SWT.NONE);
> }
>
> topRight.pack();
> final FormData trFormData = new FormData();
> trFormData.left = new FormAttachment(0, 0);
> trFormData.top = new FormAttachment(0);
> trFormData.width = shell.getClientArea().width - topLeft.getSize().x -
> 5;
> topRight.setLayoutData(trFormData);
>
> trScroller.setContent(topRight);
>
>
> // Bottom Left
>
> final ScrolledComposite blScroller = new ScrolledComposite (shell,
> SWT.V_SCROLL);
> blScroller.setExpandVertical(true);
> final FormData blScrollerFormData = new FormData();
> blScrollerFormData.left = new FormAttachment(0, 5);
> blScrollerFormData.top = new FormAttachment(topLeft, 5);
> blScrollerFormData.width = 244;
> blScroller.setLayoutData(blScrollerFormData);
> final Table bottomLeft = new Table(blScroller,SWT.SINGLE |
> SWT.FULL_SELECTION);
> bottomLeft.setHeaderVisible(true);
> bottomLeft.setLinesVisible(true);
> TableColumn blColumn1 = new TableColumn(bottomLeft,SWT.LEFT);
> blColumn1.setWidth(200);
> TableColumn blColumn2 = new TableColumn(bottomLeft,SWT.LEFT);
> blColumn2.setWidth(60);
> for (int i=0; i<12; i++) {
> TableItem item = new TableItem (bottomLeft, SWT.NONE);
> item.setText(new String[] {"Row " , String.valueOf(i)});
> }
> bottomLeft.pack();
> FormData blFormData = new FormData();
> blFormData.width = 244;
> blFormData.left = new FormAttachment(0, 0);
> blFormData.top = new FormAttachment(0);
> bottomLeft.setLayoutData(blFormData);
> blScroller.setContent(bottomLeft);
>
> // Bottom right
>
> final ScrolledComposite brScroller = new ScrolledComposite (shell,
> SWT.NONE);
> brScroller.setExpandHorizontal(true);
> brScroller.setExpandVertical(true);
> final Table bottomRight = new Table(brScroller,SWT.SINGLE|
> SWT.FULL_SELECTION | SWT.HIDE_SELECTION );
> bottomRight.setHeaderVisible(false);
> bottomRight.setLinesVisible(true);
> for (int i = 0; i < 10; i++) {
> TableColumn tableColumn = new TableColumn(bottomRight,SWT.CENTER);
> tableColumn.setWidth(80);
> }
>
> for (int i=0; i<12; i++) {
> TableItem item = new TableItem (bottomRight, SWT.NONE);
> String [] line = new String[10];
> for (int j = 0; j < line.length; j++) {
> line[j] = String.valueOf(i*10+j);
> }
> item.setText(line);
> }
>
> bottomRight.pack();
> final FormData brFormData = new FormData();
> brFormData.left = new FormAttachment(blScroller, 5);
> brFormData.top = new FormAttachment(trScroller, 0);
> brFormData.width = shell.getClientArea().width - topLeft.getSize().x -
> 5;
> brScroller.setLayoutData(brFormData);
> brScroller.setContent(bottomRight);
>
>
> shell.addControlListener(new ControlAdapter() {
> public void controlResized(ControlEvent event) {
> Shell shell = (Shell)event.getSource();
> Rectangle rect = shell.getClientArea();
> trFormData.width = rect.width - topLeft.getSize().x - 5;
> trScrollerFormData.width = rect.width - topLeft.getSize().x - 5;
> brFormData.width = rect.width - topLeft.getSize().x - 5;
> brFormData.height = rect.height - topRight.getSize().y - 5;
> shell.layout();
> }
> });
>
>
> final ScrollBar trScrollBar = trScroller.getHorizontalBar();
> trScrollBar.addSelectionListener( new SelectionAdapter () {
> public void widgetSelected (SelectionEvent e) {
>
> // >>>> This does not fire <<<<
> System.out.println("trScrollBar " + trScrollBar.getSelection () + "
> " + trScrollBar.getSelection ());
> brScroller.setOrigin(trScrollBar.getSelection(), 0);
> }
> });
>
> final ScrollBar brScrollBar = trScroller.getHorizontalBar();
> brScrollBar.addSelectionListener( new SelectionAdapter () {
> public void widgetSelected (SelectionEvent e) {
>
> // >>>> This does not fire <<<<
> System.out.println("brScrollBar " + brScrollBar.getSelection () + "
> " + brScrollBar.getSelection ());
> brScroller.setOrigin(trScrollBar.getSelection(), 0);
> }
> });
>
> shell.open ();
>
> Rectangle rect = shell.getClientArea();
> trFormData.width = rect.width - topLeft.getSize().x - 5;
> trScrollerFormData.width = rect.width - topLeft.getSize().x - 5;
> brFormData.width = rect.width - topLeft.getSize().x - 5;
> brFormData.height = rect.height - topRight.getSize().y - 5;
> shell.layout();
>
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }
> }
>
|
|
| |
Goto Forum:
Current Time: Wed Apr 24 21:36:13 GMT 2024
Powered by FUDForum. Page generated in 0.03361 seconds
|