MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Getting the height and width of controls?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98924] Re: Getting the height and width of controls?
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Wed, 22 Apr 2009 05:09:22 -0400 (EDT)
  • References: <gsivdl$9b1$1@smc.vnet.net> <gsk2i3$o0v$1@smc.vnet.net>

Hi,

> ok, so far this is what I stumbled upon, but it dones't work right:
> 
> t = Button["Click Here", Print[10!]]
> AbsoluteCurrentValue[bt, ImageSize]
> 
> That code always gives {350,350}. Lots of other options work, but not
> getting the height/width of a control.
> I can't use CurrentValue for that works only when I actually click the
> button, but it too gives only the same answer.
> I didnt think getting the simple height/width of a control to be that
> hard?? 

unfortunatly it is not easy to get that information. The reason is I
think that the visual representation of the Button lives in the
frontend, so the kernel has no idea of what sizes it may have. Only for
objects like notebooks, where the kernel has a handle to the actual
object you can use AbsoluteOptions the way you did.

> If there is a better way, please teach me. Thanks

for controls like Button there is only one way I know to get the
information you want: you need to Rasterize it, which gives you a
Graphics-Object, which you can then ask for its ImageSize in the usual way.

bt = Button["Click Here", Print[10!]];

Options[Rasterize[bt], ImageSize]

This also works for other things that are formatted by the Frontend like
Grid for example:

grid = Grid[RandomInteger[{0, 200}, {2, 8}], Dividers -> All]

Options[Rasterize[grid], ImageSize]

hth,

albert


  • Prev by Date: Re: Mathematica in conjunction with outside program; NMinimize fails.
  • Next by Date: Re: Re: Mathematica for gifted elementary school children
  • Previous by thread: Re: Getting the height and width of controls?
  • Next by thread: Creating a sign chart