1
$\begingroup$

Consider the following code:

info = {};
CreatePalette[
  CreatePalette[
   Dynamic[
    Grid[Transpose[info], Dividers -> All, ItemSize -> Full]],
   WindowSize -> {150, 150},
   WindowMargins -> {{0, Automatic}, {Automatic, 0}},
   WindowElements -> {"HorizontalScrollBar"},
   WindowTitle -> "SecondPalette"];

  mydata = {100, 200, 300};
  Column[{TextCell[Row[{"My data is: ", mydata}]],
    Button["Add data", AppendTo[info, mydata]]}],

  WindowSize -> {150, 150},
  WindowTitle -> "First Palette"];

Mathematica graphics


When you execute this code, you see two palettes. The rightmost palette (named "FirstPalette", controls entry of data into the leftmost palette (named "SecondPalette").

Notice when you click the "Add data" button, data is dynamically updated in the SecondPalette.

When the size of data inside SecondPalette becomes larger than the size of the palette window (press Add data 6 times in a row), the HorizontalScrollBar does not activate like I was hoping it would.

Question A: Is there a way to get the scrollbar to activate when using a data-entry process like the one illustrated in this toy example? (i.e., I need the interaction between palettes to activate the scrollbar when the data becomes too large to hold inside a window.)

Question B: Is there a way to force a window to display a scrollbar even if the window's content is smaller than the size of the window? (I know this sounds odd, but if I can't get a solution to question A, I thought maybe there would be a way to always have the scrollbar displayed?)

$\endgroup$
2
  • $\begingroup$ I would use Pane inside Grid, using the ImageSize option. $\endgroup$ Commented Sep 7, 2015 at 21:48
  • $\begingroup$ Thank you for your comment, Rolf. It was just the advice I needed to overcome trouble spots in my code. I never really appreciated the value of Pane until now. Much appreciated! $\endgroup$
    – Todd Allen
    Commented Sep 9, 2015 at 23:06

1 Answer 1

1
$\begingroup$

Following the advice of Rolf Mertig, I modified my code to include Pane outside Grid, coupled with an appropriate ImageSize, and now the code allows the palette's scroll bars to activate.

Here is the corrected code:

info = {};
CreatePalette[
  CreatePalette[
   Dynamic[
    Pane[Grid[Transpose[info], Dividers -> All, ItemSize -> Full], 
     ImageSize -> 1000]],
   WindowSize -> {150, 150},
   WindowMargins -> {{0, Automatic}, {Automatic, 0}},
   WindowElements -> {"HorizontalScrollBar"},
   WindowTitle -> "SecondPalette"];

  mydata = {100, 200, 300};
  Column[{TextCell[Row[{"My data is: ", mydata}]],
    Button["Add data", AppendTo[info, mydata]]}],

  WindowSize -> {150, 150},
  WindowTitle -> "First Palette"];

Until this moment, I never really appreciated what Pane can do for user interface construction. Basically, it allows you to define an arbitrarily sized space (via its ImageSize option), that can be placed inside a palette/notebook/window of smaller size. As long as the code allows for the window to use scroll bars, the larger Pane inside the window will trigger activation of the scroll bars. This is exactly the behavior I was struggling to achieve.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.