Forum: Ruby FXRuby: updating a text label/positioning question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2006-06-05 17:01
(Received via mailing list)
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
Lyle J. (Guest)
on 2006-06-05 19:28
(Received via mailing list)
On 6/5/06, removed_email_address@domain.invalid 
<removed_email_address@domain.invalid> 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...

<snip>

> 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.
This topic is locked and can not be replied to.