2
$\begingroup$

Given the following example, how can I make each Framed object to fill its Grid cell both vertically and horizontally? Obviously, Grid calculates some cell sizes, that Button knows of (as andre314 has pointed out), but not Framed, Pane, Panel, etc. How can I reproduce the behaviour of Button with other constructs without relying on explicit numbers?

ClearAll[b, f1, f2];

b = Button[#, Background -> LightGray, ImageSize -> Full] &;
f1 = Framed[#, Background -> LightGray, RoundingRadius -> 5] &;
f2 = Framed[#, Background -> LightGray, RoundingRadius -> 5, ImageSize -> Full] &;

Grid[{{b@"321\n123", b@"123456789"}, {b@"321", SpanFromLeft}}, 
   Spacings -> {0, 0}, Frame -> None],
Grid[{{f1@"321\n123", f1@"123456789"}, {f1@"321", SpanFromLeft}}, 
   Spacings -> {0, 0}, Frame -> None],
Grid[{{f2@"321\n123", f2@"123456789"}, {f2@"321", SpanFromLeft}}, 
   Spacings -> {0, 0}, Frame -> None]

enter image description here

$\endgroup$

1 Answer 1

6
$\begingroup$

I propose a workaround, in case nobody find something better.

If you replace Framed by Button it gives :

Grid[{{Button["321\n123", Background -> Yellow, RoundingRadius -> 5], 
   Button["123456789", Background -> Green, 
    RoundingRadius -> 5]}, {Button["321", Background -> Cyan, 
    RoundingRadius -> 5], SpanFromLeft}}, Spacings -> {0, 0}, 
 Frame -> All, FrameStyle -> Black]  

enter image description here

$\endgroup$
2
  • $\begingroup$ This is nice! I certainly want to have a general method where I can use any construct inside, not just Button. I wonder, what hidden option or internal property of Button ensures this behaviour that is missing from e.g. Frame? No matter of how I specify ImageSize within Button, I cannot explicitly reproduce it. $\endgroup$ Commented Mar 18 at 9:01
  • $\begingroup$ In the past, I have tried a little bit to reproduce the behaviour of Button on another object (I don't remember which one) : no success. $\endgroup$
    – andre314
    Commented Mar 18 at 17:55

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.