# Scrolling to the newly appended row in an FXTable

**URL:** <https://www.ruby-forum.com/t/scrolling-to-the-newly-appended-row-in-an-fxtable/117042>\
**Category:** FXRuby\
**Created:** [October 12, 2007, 11:44am UTC](https://www.ruby-forum.com/t/scrolling-to-the-newly-appended-row-in-an-fxtable/117042 "2007-10-12T11:44:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![philpraxis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@philpraxis](https://www.ruby-forum.com/u/philpraxis)\
**Post date:** [October 12, 2007, 11:44am UTC](https://www.ruby-forum.com/t/scrolling-to-the-newly-appended-row-in-an-fxtable/117042/1 "2007-10-12T11:44:58Z")

</div>

Hi,

After appending a row in an FXTable, I’d like to scroll the FXTable to  
the last line of the FXTable, to make sure the new row is visible.

I’m using this kind of code:

def onInsertRow(sender, sel, ptr)  
@table.appendRows(1, true)  
@table.setPosition(0, -1000) # I never have more that 1000 lines  
in the table!  
end

The problem is that I’m unable to scroll until the last line, only the  
line \*\*\* before the last line \*\*\*. Apparently, it’s a “timing” problem:  
when position is set, the line append is not completely “committed” to  
the GUI.

Called separately, @table.setPosition(0, -1000) works just fine, as you  
can see in this test:

* * *

#!/usr/bin/env ruby

require ‘fox16’  
require ‘date’

include Fox

class TableWindow \< FXMainWindow

def initialize(app)  
# Call the base class initializer first  
super(app, “Table Widget Test”, :opts =\> DECOR\_ALL)

```
# Tooltip
tooltip = FXToolTip.new(getApp())

# Menubar
menubar = FXMenuBar.new(self, LAYOUT_SIDE_TOP|LAYOUT_FILL_X)

# Separator
FXHorizontalSeparator.new(self,

```

LAYOUT\_SIDE\_TOP|LAYOUT\_FILL\_X|SEPARATOR\_GROOVE)

```
# Contents
contents = FXVerticalFrame.new(self,

```

LAYOUT\_SIDE\_TOP|FRAME\_NONE|LAYOUT\_FILL\_X|LAYOUT\_FILL\_Y)

```
frame = FXVerticalFrame.new(contents,
  FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y, :padding =>

```

1. 

```
# Table
@table = FXTable.new(frame,
  :opts =>

```

TABLE\_COL\_SIZABLE|TABLE\_ROW\_SIZABLE|LAYOUT\_FILL\_X|LAYOUT\_FILL\_Y,  
:padding =\> 2)

```
@table.visibleRows = 10
@table.visibleColumns = 4

@table.setTableSize(20, 14)

# Initialize column headers
(0...12).each { |c| @table.setColumnText(c, Date::MONTHNAMES[c+1])

```

}

```
# Initialize row headers
(0...20).each { |r| @table.setRowText(r, "Row#{r}") }

# File Menu
filemenu = FXMenuPane.new(self)
FXMenuCommand.new(filemenu, "&Quit\tCtl-Q", nil, getApp(),

```

FXApp::ID\_QUIT)  
FXMenuTitle.new(menubar, “&File”, nil, filemenu)

```
# Manipulations Menu
manipmenu = FXMenuPane.new(self)

FXMenuCommand.new(manipmenu, "Insert Row").connect(SEL_COMMAND,

```

method(:onInsertRow))  
FXMenuCommand.new(manipmenu, “Go to last row”).connect(SEL\_COMMAND,  
method(:onCmdGoToLastRow))

```
FXMenuTitle.new(menubar, "&Manipulations", nil, manipmenu)

```

end

def onCmdGoToLastRow(sender, sel, ptr)  
@table.setPosition(0, -1000)  
end

def onInsertRow(sender, sel, ptr)  
@table.appendRows(1, true)  
@table.setPosition(0, -1000)  
end

# Create and show this window

def create  
super  
show(PLACEMENT\_SCREEN)  
end  
end

# Start the whole thing

if **FILE** == $0

# Make application

application = FXApp.new(“TableApp”, “FoxTest”)

# Make window

TableWindow.new(application)

# Create app

application.create

# Run

application.run  
end

* * *

Any idea how I can do that?

Thanks!

Philippe L.

---

<div class="post-metadata">

**Author:** ![philpraxis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@philpraxis](https://www.ruby-forum.com/u/philpraxis)\
**Post date:** [December 12, 2012, 1:36pm UTC](https://www.ruby-forum.com/t/scrolling-to-the-newly-appended-row-in-an-fxtable/117042/2 "2012-12-12T13:36:22Z")

</div>

You have to call after appends the row:

@table.create  
@table.recalc  
@table.layout

Then you have to go to the new position.
