Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to scroll a table to its end
How to scroll a table to its end [message #458951] Wed, 27 July 2005 08:46 Go to next message
Vincent Etter is currently offline Vincent EtterFriend
Messages: 72
Registered: July 2009
Member
Hello !

I want to scroll a table to its end after the user has added an item, so
that the user can see directly that the item has been added instead of
having to scroll the whole table down.

After looking in the API I found the setTopIndex(int index) method of
the Table class but it does not want I want : the last element is
sometimes "cut" because the table's height isn't exactly a multiple of
rows' height.

How can I solve that ? Is there a "setBottomIndex()" method hidden
somewhere ;) ?

Thanks ;) !

Vincent
Re: How to scroll a table to its end [message #458958 is a reply to message #458951] Wed, 27 July 2005 12:38 Go to previous messageGo to next message
Yves Harms is currently offline Yves HarmsFriend
Messages: 80
Registered: July 2009
Member
Hi,
try mytable.getItem(table.getItemCount()-1).showItem()
or newItem.showItem() if you already have a reference to the new item.

Yves

> Hello !
>
> I want to scroll a table to its end after the user has added an item, so
> that the user can see directly that the item has been added instead of
> having to scroll the whole table down.
>
> After looking in the API I found the setTopIndex(int index) method of
> the Table class but it does not want I want : the last element is
> sometimes "cut" because the table's height isn't exactly a multiple of
> rows' height.
>
> How can I solve that ? Is there a "setBottomIndex()" method hidden
> somewhere ;) ?
>
> Thanks ;) !
>
> Vincent
Re: How to scroll a table to its end [message #458960 is a reply to message #458958] Wed, 27 July 2005 12:58 Go to previous messageGo to next message
Vincent Etter is currently offline Vincent EtterFriend
Messages: 72
Registered: July 2009
Member
Yves Harms wrote:
> Hi,
> try mytable.getItem(table.getItemCount()-1).showItem()
> or newItem.showItem() if you already have a reference to the new item.
>
> Yves

Thanks for your answer ! The right code is :

TableItem lastItem = myTable.getItem(restoreItemsTable.getItemCount() - 1);
myTable.showItem(lastItem);

But unfortunately the result is the same as with setTopIndex() : the
last item is most of the time "cut" :(...
Re: How to scroll a table to its end [message #458963 is a reply to message #458960] Wed, 27 July 2005 13:26 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Vincent,

Which platform do you see this on? Do you have a snippet that shows it
happening? I did a quick experiment (snippet below) on win32, gtk and
motif, and could not get any of them to cut off the last item, even with
various Table heights. Using Table.setTopIndex() with a large value (eg.-
setTopIndex(table.getItemCount() - 1)) _should_ do what you want.

public class Main {
static int TABLE_HEIGHT = 195;
static int TABLE_ITEMCOUNT = 100;
public static void main(String[] args) {
Display display = new Display ();
final Shell shell = new Shell(display);
shell.setBounds(10,10,300,300);
final Table table = new Table(shell, SWT.NONE);
table.setBounds(10,10,200,TABLE_HEIGHT);
for (int i = 0; i < TABLE_ITEMCOUNT; i++) {
new TableItem (table, SWT.NONE).setText("item " + i);
}
shell.open();
shell.addListener(SWT.MouseDown, new Listener() {
public void handleEvent(Event event) {
TableItem lastItem = table.getItem(TABLE_ITEMCOUNT - 1);
table.showItem(lastItem);
//table.setTopIndex(TABLE_ITEMCOUNT - 1);
}
});
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
}

Grant

"Vincent Etter" <vincent.etter@gmail.com> wrote in message
news:dc80d6$tbf$1@news.eclipse.org...
> Yves Harms wrote:
> > Hi,
> > try mytable.getItem(table.getItemCount()-1).showItem()
> > or newItem.showItem() if you already have a reference to the new item.
> >
> > Yves
>
> Thanks for your answer ! The right code is :
>
> TableItem lastItem = myTable.getItem(restoreItemsTable.getItemCount() -
1);
> myTable.showItem(lastItem);
>
> But unfortunately the result is the same as with setTopIndex() : the
> last item is most of the time "cut" :(...
Re: How to scroll a table to its end [message #458966 is a reply to message #458963] Wed, 27 July 2005 14:04 Go to previous messageGo to next message
Vincent Etter is currently offline Vincent EtterFriend
Messages: 72
Registered: July 2009
Member
Grant,

I'm running on Windows XP. Your snippet works fine but not my code...
Here is a screenshot of what I get :

http://img59.imageshack.us/img59/4816/screenshot3ur.jpg

This is really strange... Thanks for your interest !

Vincent
Re: How to scroll a table to its end [message #458968 is a reply to message #458966] Wed, 27 July 2005 14:31 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
There's something strange happening with the TableEditor (just logged
https://bugs.eclipse.org/bugs/show_bug.cgi?id=105316 ), though I have not
replicated your problem. If you have a stand-alone snippet that shows it
happening then it would be easier to determine what's happening in your
case.

Grant

"Vincent Etter" <vincent.etter@gmail.com> wrote in message
news:dc8497$2o2$1@news.eclipse.org...
> Grant,
>
> I'm running on Windows XP. Your snippet works fine but not my code...
> Here is a screenshot of what I get :
>
> http://img59.imageshack.us/img59/4816/screenshot3ur.jpg
>
> This is really strange... Thanks for your interest !
>
> Vincent
Re: How to scroll a table to its end [message #458971 is a reply to message #458968] Wed, 27 July 2005 14:53 Go to previous message
Vincent Etter is currently offline Vincent EtterFriend
Messages: 72
Registered: July 2009
Member
Grant Gayed wrote:
> There's something strange happening with the TableEditor (just logged
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=105316 ), though I have not
> replicated your problem. If you have a stand-alone snippet that shows it
> happening then it would be easier to determine what's happening in your
> case.
>
> Grant

My problem is the same as the one you reported. The stand-alone snippet
I made shows the same than your screenshot in the bug report. Here it is :

public class Main {

static int TABLE_HEIGHT = 195;
static int TABLE_ITEMCOUNT = 100;

public static void main(String[] args) {
Display display = new Display ();
final Shell shell = new Shell(display);
shell.setBounds(10,10,300,300);

final Table table = new Table(shell, SWT.NONE);
table.setBounds(10,10,200,TABLE_HEIGHT);
new TableColumn(table, SWT.NONE).setWidth(75);
new TableColumn(table, SWT.NONE).setWidth(75);

for (int i = 0; i < TABLE_ITEMCOUNT; i++) {
TableItem item = new TableItem(table, SWT.NONE);

Label label = new Label(table, SWT.NONE);
label.setText("item " + i);

label.setBackground(Display.getCurrent().getSystemColor(SWT. COLOR_WHITE));
label.pack();
TableEditor editor = new TableEditor(table);
editor.grabHorizontal = true;
editor.grabVertical = true;
editor.setEditor(label, item, 0);

Button remove = new Button(table, SWT.PUSH);
remove.setText("Remove");
remove.pack();
editor = new TableEditor(table);
editor.minimumWidth = remove.getSize().x;
editor.setEditor(remove, item, 1);
table.getColumn(1).setWidth(remove.getSize().x + 5);
}

shell.open();
shell.addListener(SWT.MouseDown, new Listener() {
public void handleEvent(Event event) {
TableItem lastItem = table.getItem(TABLE_ITEMCOUNT - 1);
table.showItem(lastItem);
//table.setTopIndex(TABLE_ITEMCOUNT - 1);
}
});
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

}

Look at the labels : you can see that the scrollbar seems to scroll but
the content of the table does not move ! Screenshot :

http://img61.imageshack.us/img61/1639/screenshot20cg.jpg
Previous Topic:"Unsupported or unrecognized format" reading jpegs
Next Topic:SWT exception kills VM
Goto Forum:
  


Current Time: Sat Oct 24 18:40:07 GMT 2020

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

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

Back to the top