MathGroup Archive 2004

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

Search the Archive

Re: MathJFrame, MathGraphicsJPanel question

  • To: mathgroup at
  • Subject: [mg47785] Re: [mg47699] MathJFrame, MathGraphicsJPanel question
  • From: Todd Gayley <tgayley at>
  • Date: Mon, 26 Apr 2004 02:42:04 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

At 01:38 AM 4/22/2004, J. McKenzie Alexander wrote:
>I have two questions concerning the use of MathJFrame and
>MathGraphicsJPanel, which basically arose while writing the graphic
>viewer at  (That
>notebook uses JLink to define a function called GraphicViewer which,
>when passed a list of graphics objects, allows one to view the graphics
>one at a time, using "Next" and "Previous" buttons to page through the
>list, or to jump to a specific point by typing an index into a text
>If you download that notebook and try it out, you'll notice two
>problems: first, the MathJFrame doesn't open at the right size... you
>have to resize it at first.  Second, the MathGraphicsJPanel doesn't
>automatically resize when the containing MathJFrame is resized.
>(1) How does one set a MathJFrame to open at a specific size?  I've
>tried calling setSize on a MathJFrame and haven't had any success in
>getting it to actually cause the MathJFrame to open at the specified


When you call pack() on the MathJFrame, it is resized to accommodate all 
the components it holds at their "preferred size". This is a standard part 
of programming with Java Swing components. To make the MathJFrame appear at 
the size you want, call its setPreferredSize() method. Change your code 
where you call pack() and setVisible() to read like this:

     mathPanel@setPreferredSize[JavaNew["java.awt.Dimension", 300, 300]];
     mathPanel@recompute[];  (* recompute to get the image at the new size *)

>(2) How might one configure a MathGraphicsJPanel to be notified when
>its containing JFrame is resized (but only at the *end* of the resize
>process) so that recompute() can be called?  One often needs to call
>recompute() on the MathGraphicsJPanel so that it is the right size.

The event you want is called componentResized in the ComponentListener 
interface. Add these lines to your GraphicViewer program to respond to this 
event by calling recompute() on the MathJPanel:

                    {{"componentResized", "componentResizedFunc"}}
     componentResizedFunc[___] := mathPanel@recompute[];

Todd Gayley
Woflram Research

  • Prev by Date: Re: bug in IntegerPart ?
  • Next by Date: Re: Incidence/frequency of numbers in lists
  • Previous by thread: MathJFrame, MathGraphicsJPanel question
  • Next by thread: David's CombinatoricaGraphics functions