[plt-scheme] list-box's maximum size of string?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Nov 18 07:28:45 EST 2008

At Tue, 18 Nov 2008 16:15:27 +0530, Veer wrote:
>  When i use following code:
> 
>    (send msg-lst set lines)
> 
>  where msg-lst is a instance of list-box%  and lines is a (listof strings)
>  it complains with following error/message :
> 
>  "set in list-box%: expected argument of type <list of strings (up to
> 200 characters)>; ...  .."
> 
>  Some of my lines are indeed more than 200 characters long.
> 
>  So how do i overcome this restriction

You can use `hierarchical-list%' from `mrlib/hierlist'.

Unfortunately, the methods on `hierarchical-list%' are different. Also,
it can be tricky to get a `hiearchical-list%' to look like a
`list-box%', if that is a concern. Some example code is below.

>  also , out of curiosity why such
>  restriction is needed?

It's a result of using old GUI toolbox layers, such as an Xt-based
widget layer under X11 and Carbon APIs under Mac OS X, which have
limits in various places. This particular limit may not have to do with
list boxes; at some point, we chose a consistent 200-character limit
for all GUI labels.

Matthew

----------------------------------------------------------------------
A simple list box:
----------------------------------------------------------------------
#lang scheme/gui

(define f (new frame% [label "List"]
               [width 200]
               [height 200]))

(define l (new list-box%
               [label #f]
               [choices '()]
               [parent f]))

(send l set (for/list ([in (in-range 100)])
              (make-string 200 #\z)))

(send f show #t)

-------------------------------------------------------------------------
hierlist simulating a list box, but without the label-width limit:
----------------------------------------------------------------------
#lang scheme/gui
(require mrlib/hierlist)

(define f (new frame% [label "List"]
               [width 200]
               [height 200]))

(define l (new hierarchical-list%
               [label #f]
               [parent f]
               [style '(control-border no-hscroll)]))
(send l set-no-sublists #t)
(send l horiz-margin 2)
(send l vert-margin 2)
(send l horizontal-inset 0)
(send l vertical-inset 0)

(define items (for/list ([i (in-range 100)])
                (make-string 201 #\z)))

(for ([i (in-list items)])
  (send (send (send l new-item) get-editor) insert i))

(send f show #t)



Posted on the users mailing list.