FXRuby: updating a text label/positioning question

Dear all,

in a GUI, I want to display some text from inside a text file in a text
field.
When starting the application, it looks roughly like this

################

filelist window

################

contents of file:
################

text field

################

Now, as the user chooses some file from above, its text should
appear inside the text field (which it does) and the name of the
file should appear above it, changing
contents of file: to contents of file: my_file.txt, if that’s
the name of the file.
I’ve searched the archive of the mailing lists, and found
a way to add a label , to recalc everything and to create the
whole frame anew:

class YourWidget < FXVerticalFrame
def addLabel(parent,text)
FXLabel.new(parent, text) do |label|
label.create
end
self.recalc
end
end

So I use :

class Mainwindow
def initialize

@header=‘contents of file’
@topFrame = FXVerticalFrame.new(self, LAYOUT_FILL_X|LAYOUT_FILL_Y)
@header_line=FXLabel.new(@topFrame, @header, nil, LAYOUT_FILL_X)

end
def loadFile

@header=self.addLabel(@topFrame,'Contents of file ’ + @filename)

end

end

but I can’t change the content of @header in its original place. How
could
that
be done ?

Thank you very much!

Best regards,

AXel

On 6/5/06, [email protected] [email protected] wrote:

I’ve searched the archive of the mailing lists, and found
a way to add a label , to recalc everything and to create the
whole frame anew…

but I can’t change the content of @header in its original place. How could
that be done ?

I didn’t follow all of that very well, but I think your question boils
down to, “How do I change the text of a label?” If that’s the
question, you change it using the text accessor method, e.g.

@header.text = "Contents of file " + new_filename

Note that you don’t have to create a new label every time, and in fact
that’s sort-of a wasteful thing to do. Better to just change the text
of the existing label widget (as shown here).

P.S. Please consider subscribing to the fxruby-users mailing list and
posting questions there instead.