Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6658845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:57:39+00:00 2026-05-26T01:57:39+00:00

I’ve been developing a gui for some time, which requires the creation of common

  • 0

I’ve been developing a gui for some time, which requires the creation of common control objects that Mathematica lacks (e.g. spinner, treeview, openerbar, etc.). One is the multipanel, i.e. a pane object that is split into two (or more) subpanes, where the divider can be set by the mouse. Here is my version of a dual pane. I would like to hear your opinion and ideas about how to expand it to handle not just 2 but any number of subpanes, and also how to optimize it. At present, for heavily loaded subpanes, it lags terribly, no idea why.

Options[SplitPane] = {Direction -> "Vertical", 
   DividerWidth -> Automatic, Paneled -> {True, True}};
SplitPane[opts___?OptionQ] := 
  Module[{dummy}, SplitPane[Dynamic[dummy], opts]];
SplitPane[val_, opts___?OptionQ] := SplitPane[val, {"", ""}, opts];
SplitPane[val_, content_, opts___?OptionQ] := 
  SplitPane[val, content, {100, 50}, opts];
SplitPane[Dynamic[split_, arg___], {expr1_, expr2_}, {maxX_, maxY_}, 
   opts___?OptionQ] := 
  DynamicModule[{temp, dir, d, panel, coord, max, fix, val},
   {dir, d, panel} = {Direction, DividerWidth, Paneled} /. {opts} /. 
     Options[SplitPane];
   dir = dir /. {Bottom | Top | "Vertical" -> "Vertical", _ -> 
       "Horizontal"};
   d = d /. Automatic -> 2;
   split = If[NumberQ[split], split, max/2];
   val = Clip[split /. {_?NumberQ -> split, _ -> maxX/2}, {0, maxX}];
   {coord, max, fix} = 
    Switch[dir, "Vertical", {First, maxX, maxY}, 
     "Horizontal", {(max - Last[#]) &, maxY, maxX}];
   panel = (# /. {None | False -> 
          Identity, _ -> (Panel[#, ImageMargins -> 0, 
             FrameMargins -> -1] &)}) & /@ panel;

   Grid[If[dir === "Vertical",
     {{
       Dynamic[
        panel[[1]]@
         Pane[expr1, ImageSize -> {split - d, fix}, 
          ImageSizeAction -> "Scrollable", Scrollbars -> Automatic, 
          AppearanceElements -> None], TrackedSymbols :> {split}],
       Deploy@EventHandler[
         MouseAppearance[
          Pane[Null, ImageSize -> {d*2, fix}, ImageMargins -> -1, 
           FrameMargins -> -1], "FrameLRResize"],
         "MouseDown" :> (temp = 
            coord@MousePosition@"CellContentsAbsolute"; 
           split = 
            If[Abs[temp - split] <= d \[And] 0 <= temp <= max, temp, 
             split]), 
         "MouseDragged" :> (temp = 
            coord@MousePosition@"CellContentsAbsolute"; 
           split = If[0 <= temp <= max, temp, split])],
       Dynamic@
        panel[[2]]@
         Pane[expr2, ImageSizeAction -> "Scrollable", 
          Scrollbars -> Automatic, AppearanceElements -> None, 
          ImageSize -> {max - split - d, fix}]
       }},
     {
      List@
       Dynamic[panel[[1]]@
         Pane[expr1, ImageSize -> {fix, split - d}, 
          ImageSizeAction -> "Scrollable", Scrollbars -> Automatic, 
          AppearanceElements -> None], TrackedSymbols :> {split}],
      List@Deploy@EventHandler[
         MouseAppearance[
          Pane[Null, ImageSize -> {fix, d*2}, ImageMargins -> -1, 
           FrameMargins -> -1], "FrameTBResize"],
         "MouseDown" :> (temp = 
            coord@MousePosition@"CellContentsAbsolute"; 
           split = 
            If[Abs[temp - split] <= d \[And] 0 <= temp <= max, temp, 
             split]), 
         "MouseDragged" :> (temp = 
            coord@MousePosition@"CellContentsAbsolute"; 
           split = If[0 <= temp <= max, temp, split])],
      List@
       Dynamic[panel[[2]]@
         Pane[expr2, ImageSizeAction -> "Scrollable", 
          Scrollbars -> Automatic, 
          ImageSize -> {fix, max - split - d}, 
          AppearanceElements -> None], TrackedSymbols :> {split}]
      }
     ], Spacings -> {0, -.1}]
   ];
SplitPane[val_, arg___] /; NumberQ[val] := 
  Module[{x = val}, SplitPane[Dynamic[x], arg]];

pos = 300;
SplitPane[
 Dynamic[pos], {Manipulate[
   Plot[Sin[x (1 + a x)], {x, 0, 6}], {a, 0, 2}], 
  Factorial[123]}, {500, 300}]

SplitPane output

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:57:40+00:00Added an answer on May 26, 2026 at 1:57 am

    The key to generalizing to several panels was to refactor your code. In its present form, while very nice, it was mixing visualization / UI primitives and options with the split logic, and had lots of duplicate code. This made generalization hard. Here is the refactored version:

    ClearAll[SplitPane];
    Options[SplitPane] = {
        Direction -> "Vertical", DividerWidth -> Automatic, Paneled -> True
    };
    SplitPane[opts___?OptionQ] :=   Module[{dummy}, SplitPane[Dynamic[dummy], opts]];
    SplitPane[val_, opts___?OptionQ] := SplitPane[val, {"", ""}, opts];
    SplitPane[val_, content_, opts___?OptionQ] :=
        SplitPane[val, content, {100, 50}, opts];
    SplitPane[sp_List, {cont__}, {maxX_, maxY_}, opts___?OptionQ] /; 
            Length[sp] == Length[Hold[cont]] - 1 :=
      Module[{scrollablePane, dividerPane, onMouseDownCode, onMouseDraggedCode, dynPane,
          gridArg, split, divider, panel},
        With[{paneled = Paneled /. {opts} /. Options[SplitPane],len = Length[Hold[cont]]},
           Which[
              TrueQ[paneled ],
                 panel = Table[True, {len}],
              MatchQ[paneled, {Repeated[(True | False), {len}]}],
                 panel = paneled,
              True,
                Message[SplitPane::badopt]; Return[$Failed, Module]
           ]
        ];
    
        DynamicModule[{temp, dir, d, coord, max, fix, val},
          {dir, d} = {Direction, DividerWidth}/.{opts}/.Options[SplitPane];
          dir =  dir /. {
             Bottom | Top | "Vertical" -> "Vertical", _ -> "Horizontal"
          };
          d = d /. Automatic -> 2;
          val = Clip[sp /. {_?NumberQ -> sp, _ -> maxX/2}, {0, maxX}];
          {coord, max, fix} =
            Switch[dir,
              "Vertical",
                 {First, maxX, maxY},
              "Horizontal",
                 {(max - Last[#]) &, maxY, maxX}
            ];
          Do[split[i] = sp[[i]], {i, 1, Length[sp]}];
          split[Length[sp] + 1] = max - Total[sp] - 2*d*Length[sp];
          panel =
              (# /. {
                None | False -> Identity, 
                _ -> (Panel[#, ImageMargins -> 0,FrameMargins -> -1] &)
               }) & /@ panel;
          scrollablePane[args___] :=
              Pane[args, ImageSizeAction -> "Scrollable", 
                   Scrollbars -> Automatic, AppearanceElements -> None];
          dividerPane[size : {_, _}] :=
              Pane[Null, ImageSize -> size, ImageMargins -> -1,FrameMargins -> -1];
    
          onMouseDownCode[n_] := 
            Module[{old},
              temp = coord@MousePosition@"CellContentsAbsolute";
              If[Abs[temp - split[n]] <= d \[And] 0 <= temp <= max,
                old = split[n];
                split[n] = temp-Sum[split[i], {i, n - 1}];
                split[n + 1] += old - split[n];       
            ]];
    
          onMouseDraggedCode[n_] :=
             Module[{old},
                temp = coord@MousePosition@"CellContentsAbsolute";
                If[0 <= temp <= max,
                   old = split[n];
                   split[n] = temp -Sum[split[i], {i, n - 1}];
                   split[n + 1] += old - split[n];
                ] ;
             ];
    
          SetAttributes[dynPane, HoldFirst];
          dynPane[expr_, n_, size_] :=
              panel[[n]]@scrollablePane[expr, ImageSize -> size];
    
          divider[n_, sizediv_, resizeType_] :=
             Deploy@EventHandler[
                MouseAppearance[dividerPane[sizediv], resizeType],
               "MouseDown" :> onMouseDownCode[n],
               "MouseDragged" :> onMouseDraggedCode[n]
             ];
    
          SetAttributes[gridArg, HoldAll];
          gridArg[{content__}, sizediv_, resizeType_, sizeF_] :=
             Module[{myHold, len = Length[Hold[content]] },
               SetAttributes[myHold, HoldAll];
               List @@ Map[
                 Dynamic,
                 Apply[Hold, 
                    MapThread[Compose,
                       {
                          Range[len] /. {
                            len :>               
                              Function[
                                 exp, 
                                 myHold[dynPane[exp, len, sizeF[len]]], 
                                 HoldAll
                              ],
                            n_Integer :>
                              Function[exp,
                                 myHold[dynPane[exp, n, sizeF[n]],
                                    divider[n, sizediv, resizeType]
                                 ], 
                              HoldAll]
                          },
                          Unevaluated /@ Unevaluated[{content}]
                        }] (* MapThread *)
                   ] /. myHold[x__] :> x
               ] (* Map *)
             ]; (* Module *)
          (* Output *)
          Grid[
            If[dir === "Vertical",
               List@ gridArg[{cont}, {d*2, fix},"FrameLRResize",{split[#] - d, fix} &],
               (* else *)
               List /@ gridArg[{cont}, {fix, d*2},"FrameTBResize", {fix, split[#] - d} &]
            ],
            Spacings -> {0, -.1}]]];
    
    SplitPane[val_, arg___] /; NumberQ[val] := 
       Module[{x = val}, SplitPane[Dynamic[x], arg]];
    

    Here is how it may look:

    SplitPane[{300, 300}, 
     {
       Manipulate[Plot[Sin[x (1 + a x)], {x, 0, 6}], {a, 0, 2}], 
       Factorial[123], 
       CompleteGraph[5]
     }, {900, 300}]
    

    enter image description here

    Can’t comment of performance problems you mentioned. Also, when you start dragging with the mouse, the real cursor position is often quite off with respect to the divider position. This is both for your and my versions, perhaps some more precise scaling is needed.

    Just want to emphasize once again – generalization became only possible after I did the refactoring, to separate the splitting logic from the visualization-related things. As to the optimization, I also think that it will be much easier to attempt optimizing this version than the original one, for the same reasons.

    EDIT

    I hesitated a bit to add this note, but it must be mentioned that my solution above, while working, shows one practice which is considered bad by expert UI mma programmers. Namely, it uses Module– generated variables inside Dynamic inner to that Module (in particular, split in the code above, also various auxiliary functions). The reasons I used it are that I wasn’t able to make this work with only DynamicModule– generated variables, plus Module– generated variables always worked for me before. However, please see the post by John Fultz in this MathGroup thread, where he states that this practice should be avoided.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.