这是一种方法,虽然不是完全令人满意,因为面板长度不是自动计算的。让我们称之为第一种方法......
Manipulate[
Graphics[{{White, Circle[{5, 5}, r]},(*For Mma 7 compatibility*)
If[MemberQ[whatToDisplay, "I am a Circle"], {Red, Circle[{5, 5}, r]}],
If[MemberQ[whatToDisplay, "and I am a very nice Square"],
{Blue, Rectangle[{5, 5}, {r, r}]}],
If[MemberQ[whatToDisplay, "Other"], {Black, Line[Tuples[{3, 4}, 2]]}]},
PlotRange -> {{0, 20}, {0, 10}}],
{{r, 1, Style["Radius", Black, Bold, 12]}, 1, 5, 1, ControlType -> Slider,
ControlPlacement -> Top},
Control@{{whatToDisplay, True, Style["What", Black, Bold, 12]},
(# -> Panel[#, ImageSize -> 150, FrameMargins -> 0,
Background -> White,
Alignment -> Center]) & /@
{"I am a Circle", "and I am a very nice Square", "Other"},
ControlType -> TogglerBar,
Appearance -> "Horizontal",
ControlPlacement -> Top}]
编辑
在这里你有一个更好的方法,自动计算大小:
(* get the Image Size first*)
ley = {"I am a Circle", "and I am Square", "Other"};
sZ = Max[Dimensions[ImageData[Rasterize[#][[1]]]][[2]] & /@ ley];
Manipulate[
Graphics[
{{White, Circle[{5, 5}, r]},(*For Mma 7 compatibility*)
If[MemberQ[whatToDisplay, "I am a Circle"],
{Red, Circle[{5, 5}, r]}],
If[MemberQ[whatToDisplay, "and I am a very nice Square"],
{Blue, Rectangle[{5, 5}, {r, r}]}],
If[MemberQ[whatToDisplay, "Other"],
{Black, Line[Tuples[{3, 4}, 2]]}]},
PlotRange -> {{0, 20}, {0, 10}}],
(*Controls Follow *)
{{r, 1, Style["Radius", Black, Bold, 12]}, 1, 5, 1,
ControlType -> Slider,
ControlPlacement -> Top },
Control@{{whatToDisplay, True, Style["What", Black, Bold, 12]},
(# -> Panel[#, ImageSize -> sZ,
FrameMargins -> 0,
Background -> White,
Alignment -> Center]) & /@ ley,
ControlType -> TogglerBar,
Appearance -> "Horizontal",
ControlPlacement -> Top}]