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 =>
0)
# 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 Lang
on 2007-10-12 11:44
on 2012-12-12 13:36
You have to call after appends the row: @table.create @table.recalc @table.layout Then you have to go to the new position.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.