# FXRuby: updating a text label/positioning question

**URL:** <https://www.ruby-forum.com/t/fxruby-updating-a-text-label-positioning-question/62487>\
**Category:** Ruby\
**Created:** [June 5, 2006, 3:01pm UTC](https://www.ruby-forum.com/t/fxruby-updating-a-text-label-positioning-question/62487 "2006-06-05T15:01:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 5, 2006, 3:01pm UTC](https://www.ruby-forum.com/t/fxruby-updating-a-text-label-positioning-question/62487/1 "2006-06-05T15:01:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 5, 2006, 5:28pm UTC](https://www.ruby-forum.com/t/fxruby-updating-a-text-label-positioning-question/62487/2 "2006-06-05T17:28:54Z")

</div>

On 6/5/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto: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…

> 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.
