Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Scroll two tables at the same time
Scroll two tables at the same time [message #444367] Tue, 12 October 2004 12:57 Go to next message
Henrik Skovgaard is currently offline Henrik SkovgaardFriend
Messages: 84
Registered: July 2009
Member
Hi

I want to be able to scroll two tables at the same time - the tables has the
same number of columns.
So if I scroll the first table, the second table scrolls to the same
position and vice versa.
I was looking for some sort of scroll listener, but couldn't find one.

Any ideas ?

/Henrik
Re: Scroll two tables at the same time [message #444368 is a reply to message #444367] Tue, 12 October 2004 13:10 Go to previous messageGo to next message
Lorenz Maierhofer is currently offline Lorenz MaierhoferFriend
Messages: 88
Registered: July 2009
Member
Hi,

> I want to be able to scroll two tables at the same time - the tables has the
> same number of columns.

I did exactly that, but was never really happy with the results.
The problem is not that it does not work, but if one table has a
horizontal scrollbar and the other doesn't, things don't look pretty
anymore. And unfortunately you can't control the visibility of table
scrollbars under windows...

(My solution was to finally switch to a custom swt table control,
KTable, that allows fixed cells).

> I was looking for some sort of scroll listener, but couldn't find one.
Look at table.setTopIndex() and getTopIndex() for checking / setting the
correct top-visible element.

You can listen to scroll events by getting the vertical and horizontal
bars of the table and add a selection listener to them.
table.getVerticalBar().addSelectionListener(...)
Re: Scroll two tables at the same time [message #444371 is a reply to message #444367] Tue, 12 October 2004 13:34 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
One way to scroll two tables vertically at the same time is to use a
ScrolledComposite and have one scrollbar for the two tables.
The solution depends on how you want your GUI to be laid out.

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
ScrolledComposite sc = new ScrolledComposite(shell, SWT.V_SCROLL);
Composite parent = new Composite(sc, SWT.NONE);
parent.setLayout(new GridLayout(2, false));

Table table1 = new Table(parent, SWT.BORDER);
TableColumn column1a = new TableColumn(table1, SWT.NONE);
TableColumn column2a = new TableColumn(table1, SWT.NONE);
for (int i = 0; i < 100; i++) {
TableItem item = new TableItem(table1, SWT.NONE);
item.setText(new String[] { "left item " + i, "column 1 " +
i });
}
column1a.pack();
column2a.pack();

Table table2 = new Table(parent, SWT.BORDER);
TableColumn column1b = new TableColumn(table2, SWT.NONE);
TableColumn column2b = new TableColumn(table2, SWT.NONE);
for (int i = 0; i < 100; i++) {
TableItem item = new TableItem(table2, SWT.NONE);
item.setText(new String[] { "right item " + i, "column 1 " +
i });
}
column1b.pack();
column2b.pack();

Point size = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT);
parent.pack();
sc.setExpandVertical(true);
sc.setContent(parent);
sc.setMinHeight(size.y);

size = shell.computeSize(SWT.DEFAULT, 200);
shell.setSize(size);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}

"Henrik Skovgaard" <hsk@reklamedata.dk> wrote in message
news:ckgk1d$44k$1@eclipse.org...
> Hi
>
> I want to be able to scroll two tables at the same time - the tables has
> the same number of columns.
> So if I scroll the first table, the second table scrolls to the same
> position and vice versa.
> I was looking for some sort of scroll listener, but couldn't find one.
>
> Any ideas ?
>
> /Henrik
>
Re: Scroll two tables at the same time [message #444374 is a reply to message #444368] Tue, 12 October 2004 14:07 Go to previous message
Henrik Skovgaard is currently offline Henrik SkovgaardFriend
Messages: 84
Registered: July 2009
Member
"Lorenz Maierhofer" <lorenz.m@gmx.at> wrote in message
news:ckgkq6$5qp$1@eclipse.org...
> Hi,
>
>> I want to be able to scroll two tables at the same time - the tables has
>> the same number of columns.
>
> I did exactly that, but was never really happy with the results.

Thanks for your replies. I'll try to run the example I got to see how it
looks. Thing is, that I DO have a horizontal scroll in one of the tables,
and not in the other.

Cheers,
/Henrik
Previous Topic:Text widgets " not intended to be subclassed."
Next Topic:update lable from timertask
Goto Forum:
  


Current Time: Tue Oct 20 12:49:25 GMT 2020

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

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

Back to the top