Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

In all my apps, I am facing a problem about placing the Gui controls inside Grid.

For this purpose, I wrote three functions.

The first function, createGridList, returns empty list.

createGridList[noOfRows_, noOfColumns_] := ConstantArray["", {noOfRows, noOfColumns}]

The second function, layoutGrid, returns a GraphicsGrid.

layoutGrid[noOfRows_, noOfColumns_, list_, meshFactor_] :=
(
   GraphicsGrid[
     list,
     ImageSize -> {((noOfColumns*meshFactor)), ((noOfRows*meshFactor))},
     Background -> RGBColor[.745, .886, 1]
     ]
)

The third function, PlaceControl, returns an updated list with the Gui elements.

placeControl[yCoOrdinate_, xCoOrdinate_, controlID_, controlWidth_, 
  controlHeight_, list1_, meshFactor_] :=
(
  rowNumber = yCoOrdinate/meshFactor;
  columnNumber = xCoOrdinate/meshFactor;
  rowSpan = controlWidth/meshFactor;
  columnSpan = controlHeight/meshFactor;
  list = list1;
  Table[
  (
    If[(i == rowNumber),
      (*True condition, i value is equals to rowNumber*)
      (
        If[(j == columnNumber),
        (*True condition,j value is equals to column Number*)
        (
          list = ReplacePart[list, {i, j} -> controlID];
          Table[
            (
            list = ReplacePart[list, {i, m} -> SpanFromLeft]
            ),
            {m, (j + 1), (j + (rowSpan - 1))}
          ];
          j = (columnNumber + (rowSpan - 1));
        )
        ]
      ),
      (*False condition, i value is not equals to rowNumber*)
      (
        If[((i > rowNumber) && (i <= ((rowNumber + columnSpan) - 1))),
          (*True condition, i value is in between rowNumber,(rowNumber+ColumnSpan)*)
          (
            If[(j == columnNumber),
            (*True condition, j value is equals to column Number*)
            (
              list = ReplacePart[list, {i, j} -> SpanFromAbove];
              Table[
                (
                list = ReplacePart[list, {i, m} -> SpanFromBoth]
                ),
                {m, (j + 1), (j + (rowSpan - 1))}
              ];
              j = (columnNumber + (rowSpan - 1));
            )
            ]
         )
       ]
       )
    ]
    ),
    {i, 1, Length[list]}, {j, 1, Length[Part[list, 1]]}
  ];
  list
)   

I am calling the above function.that corresponding code is following below.

(*The following variable specifies the no of rows in grid*)
noOfRows =20;
(*The following variable specifies the no of columns in grid*)
noOfColumns = 20;
(*The following variable specifies the Button visualization*)
buttonElement = Button["Ok", "", ImageSize -> {150, 60}];
(*The following variable specifies the each cell size in grid*)
cellSize = 10;
(*The following code corresponds to the calling the above functions*)
list = createGridList[noOfRows, noOfColumns];
list = Quiet[placeControl[20, 40, Button["Ok", "", ImageSize -> {150, 60}], 
  150, 60, list, cellSize]];
layoutGrid[noOfRows, noOfColumns, list, cellSize]

Visualization-wise and logical-wise everything is fine, but the problem is: If you place so many Gui-elements inside a GraphicsGrid, it takes more time for evaluation.

My understanding is that GraphicsGrid slows down because GraphicsGrid converts all the Gui-elements into Graphics,

How can I reduce and improve the code?

share|improve this question

marked as duplicate by Jens, Yves Klett, Artes, rm -rf Apr 27 '13 at 20:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Where is the function layoutGrid defined? –  bill s Apr 27 '13 at 15:27
    
can't you simply use grid, instead of graphics grid? –  magma Apr 27 '13 at 15:27
add comment

1 Answer 1

Use Grid instead of GraphicsGrid

share|improve this answer
    
but we can't set the ImageSize for the Grid,as Grid don't have ImageSize option. –  subbu Apr 27 '13 at 17:00
add comment

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