ScrolledComposite scrol bar event not firing on Windows XP [message #464016] |
Wed, 16 November 2005 14:40 |
Eclipse User |
|
|
|
Originally posted by: mike.swt.demon.co.uk
I have seen the snippets example of scrolling two tables from one scroll
bar - I have run it and it works fine. I then created a UI with 4 tables -
like using a split in Excel - but the SelectionEvent does not fire. Is it
because I am using a different layout ?
I have condensed the code to contain just two table to illustrate the point
If you run the code, you will see that the widgetSelected method does not
get run
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 TwoTableScrollTest {
public static void main(String[] args) {
TwoTableScrollTest tableScrollTest = new TwoTableScrollTest();
tableScrollTest.run();
}
public void run() {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setSize (400, 400);
FormLayout formLayout = new FormLayout();
shell.setLayout(formLayout);
// Top
final ScrolledComposite topScroller = new ScrolledComposite (shell,
SWT.H_SCROLL );
FormLayout topFormLayout = new FormLayout();
topScroller.setLayout(topFormLayout);
topScroller.setExpandHorizontal(true);
final FormData topScrollerFormData = new FormData();
topScrollerFormData.top = new FormAttachment(0);
topScrollerFormData.width = shell.getClientArea().width;
topScroller.setLayoutData(topScrollerFormData);
final Table topTable = new Table(topScroller,SWT.SINGLE|
SWT.FULL_SELECTION | SWT.HIDE_SELECTION );
topTable.setHeaderVisible(true);
topTable.setLinesVisible(false);
for (int i = 0; i < 10; i++) {
TableColumn tableColumn = new TableColumn(topTable,SWT.CENTER);
tableColumn.setWidth(80);
}
for (int i=0; i<2; i++) {
new TableItem (topTable, SWT.NONE);
}
topTable.pack();
final FormData topFormData = new FormData();
topFormData.left = new FormAttachment(0, 0);
topFormData.top = new FormAttachment(0);
topFormData.width = shell.getClientArea().width;
topTable.setLayoutData(topFormData);
topScroller.setContent(topTable);
// Bottom
final ScrolledComposite bottomScroller = new ScrolledComposite (shell,
SWT.NONE);
bottomScroller.setExpandHorizontal(true);
bottomScroller.setExpandVertical(true);
final Table bottomTable = new Table(bottomScroller,SWT.SINGLE|
SWT.FULL_SELECTION | SWT.HIDE_SELECTION );
bottomTable.setHeaderVisible(false);
bottomTable.setLinesVisible(true);
for (int i = 0; i < 10; i++) {
TableColumn tableColumn = new TableColumn(bottomTable,SWT.CENTER);
tableColumn.setWidth(80);
}
for (int i=0; i<12; i++) {
TableItem item = new TableItem (bottomTable, 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);
}
bottomTable.pack();
final FormData bottomFormData = new FormData();
bottomFormData.top = new FormAttachment(topScroller, 0);
bottomFormData.width = shell.getClientArea().width;
bottomScroller.setLayoutData(bottomFormData);
bottomScroller.setContent(bottomTable);
shell.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent event) {
Shell shell = (Shell)event.getSource();
Rectangle rect = shell.getClientArea();
bottomFormData.height = rect.height - topTable.getSize().y - 5;
shell.layout();
}
});
final ScrollBar topScrollBar = topScroller.getHorizontalBar();
topScrollBar.addSelectionListener( new SelectionAdapter () {
public void widgetSelected (SelectionEvent e) {
// >>>> This does not fire <<<<
System.out.println("topScrollBar " + topScrollBar.getSelection () +
" " + topScrollBar.getSelection ());
bottomScroller.setOrigin(topScrollBar.getSelection(), 0);
}
});
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
|
|
|
Re: ScrolledComposite scrol bar event not firing on Windows XP [message #464085 is a reply to message #464016] |
Wed, 16 November 2005 18:10 |
Veronika Irvine Messages: 1272 Registered: July 2009 |
Senior Member |
|
|
You need to create the bottom scrolled composite with H_SCROLL too. You
need to set some minimum width when using the expandHorizontal method.
Setting a layout on ScrolledComposite has no effect (and consequently,
setting layout data on the children has no effect either).
public void run() {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setSize (400, 400);
FormLayout formLayout = new FormLayout();
shell.setLayout(formLayout);
// Top
final ScrolledComposite topScroller = new ScrolledComposite (shell,
SWT.H_SCROLL );
final FormData topScrollerFormData = new FormData();
topScrollerFormData.top = new FormAttachment(0, 5);
topScrollerFormData.left = new FormAttachment(0, 5);
topScrollerFormData.right = new FormAttachment(100, -5);
topScroller.setLayoutData(topScrollerFormData);
final Table topTable = new Table(topScroller,SWT.SINGLE|
SWT.FULL_SELECTION | SWT.HIDE_SELECTION );
topTable.setHeaderVisible(true);
topTable.setLinesVisible(false);
for (int i = 0; i < 10; i++) {
TableColumn tableColumn = new TableColumn(topTable,SWT.CENTER);
tableColumn.setWidth(80);
}
for (int i=0; i<2; i++) {
new TableItem (topTable, SWT.NONE);
}
topScroller.setExpandHorizontal(true);
topScroller.setMinWidth(topTable.computeSize(-1, -1).x);
topTable.pack();
topScroller.setContent(topTable);
// Bottom
final ScrolledComposite bottomScroller = new ScrolledComposite (shell,
SWT.H_SCROLL);
final Table bottomTable = new Table(bottomScroller,SWT.SINGLE|
SWT.FULL_SELECTION | SWT.HIDE_SELECTION );
bottomTable.setHeaderVisible(false);
bottomTable.setLinesVisible(true);
for (int i = 0; i < 10; i++) {
TableColumn tableColumn = new TableColumn(bottomTable,SWT.CENTER);
tableColumn.setWidth(80);
}
for (int i=0; i<12; i++) {
TableItem item = new TableItem (bottomTable, 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);
}
bottomScroller.setExpandHorizontal(true);
bottomScroller.setContent(bottomTable);
bottomScroller.setMinWidth(bottomTable.computeSize(-1, -1).x);
bottomTable.pack();
final FormData bottomFormData = new FormData();
bottomFormData.top = new FormAttachment(topScroller, 5);
bottomFormData.left = new FormAttachment(0, 5);
bottomFormData.right = new FormAttachment(100, -5);
bottomScroller.setLayoutData(bottomFormData);
final ScrollBar topScrollBar = topScroller.getHorizontalBar();
topScrollBar.addSelectionListener( new SelectionAdapter () {
public void widgetSelected (SelectionEvent e) {
// >>>> This does not fire <<<<
System.out.println("topScrollBar " + topScrollBar.getSelection () +
" " + topScrollBar.getSelection ());
// the following code only works because both tables have the same
number of columns and the same column widths
// The code in the following snippet has a better algorithm:
//
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet167.java?rev=HEAD& amp;content-type=text/vnd.viewcvs-markup
// int x = hBar1.getSelection() * (hBar2.getMaximum() -
hBar2.getThumb()) / Math.max(1, hBar1.getMaximum() - hBar1.getThumb());
// sc2.setOrigin (x, 0);
bottomScroller.setOrigin(topScrollBar.getSelection(), 0);
}
});
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.03319 seconds