[plt-scheme] text-field%

From: Robert Bruce Findler (robby at cs.uchicago.edu)
Date: Fri Feb 21 10:36:46 EST 2003

It isn't difficult to do most things, you just get the text object
underlying the text-field (via the get-editor) method and then do
whatever you want to it. Here's an example of colored text:

(define f (instantiate frame% ()
            (label "frame")
            (parent #f)
            (width 400)))
(define tf (instantiate text-field% ()
             (label #f)
             (parent f)
             (callback void)))

(send tf set-value "abcdef")
(define colored-style (make-object style-delta%))
(send colored-style set-delta-foreground "forest green")
(define e (send tf get-editor))
(send e change-style colored-style 0 (send e last-position))

(send f show #t)

Alignment, however, is not very well supported yet for text objects. It
works fine if you never edit the text, but when someone is typing in
the text-field%, strange things can happen. You can work around this
for simple things (like always centering) by making your own text%
subclass and setting up an editor-canvas% yourself rather than making a
text-field. It is a bit more complex than the above, tho.

Robby

At Fri, 21 Feb 2003 09:03:09 +0100, "Gerhard Bitsch" wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> Is there a (preferably easy) way to change alignment and color in a
> text-field?
> 
> Gerhard Bitsch
> Kepler-Gymnasium Tübingen
> 
> 



Posted on the users mailing list.