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.

I have created a grid, and also made a list of control objects(ex:inputfields, buttons, etc..). Then, I lay the list in my grid. There is no problem. However, the final layout takes a lot of time. I timed each operation and realized that the final grid layout is the one that takes up a huge chunk of time. Is there a better way of controlling the execution time of the graphics grid.

mygrid = ConstantArray["", {100, 100}]; mybutton1 = Button["Example", ImageSize -> {40, 50}]; myinput2 = InputField[x]; updatedlist = {}; updatedlist = ReplacePart[mygrid, {1, 2} -> mybutton1]; updatedlist = ReplacePart[updatedlist, {2, 3} -> myinput2]; Panel[GraphicsGrid[updatedlist, ImageSize -> {30, 40}, ContentSelectable -> True]]

The above code takes a lot of time to execute. I used the Timing function of mathematica to figure out which part took the long time to execute and it was the Panel[GraphicsGrid[updatedlist, ImageSize -> {30, 40}, ContentSelectable -> True]] part that was the longest. Because of this, my entire application has slowed down. Can I finetune my code to improve the performance? Look forward to hearing your inputs!

Based on the comments blow, I tried to use a grid for the updatedlist above, but the problem is, how can I set the ImageSize of the Gridwhich is an option for the GraphicsGrid and not Grid?

Thanks in advance,Anuk

share|improve this question
    
you might want to mark your additional question in a more prominent fashion, e.g. using a bold heading like EDIT or such. See the Grid help for defining the ImageSize for items. –  Yves Klett Feb 21 '13 at 18:09
add comment

1 Answer

The reason for the slow response is that GraphicsGrid needs to convert $100\times 100 = 10000$ cells into graphics. For an interactive interface, you should use Grid instead of GraphicsGrid. If you do need graphics in the grid, they can be put into the cells of the Grid. You don't need to convert the entire layout into Graphics.

share|improve this answer
    
My idea is to have a customized layout that can dynamically change itself itself depending on the requirements of the user interface which is why I am using Graphicsgrid which provides a lot of options for ImageSize. For sake of testing I did do this, I put my list in Grid and placed it in GraphicsGrid. Even though the execution time is faster, the control buttons are way off in the layout the with their sides being cut, improperly displayed, etc. Converting the entire layout gives accurate graphical versions of control objects but takes up a lot of time. –  Anuk Jan 30 '13 at 6:38
1  
@Anuk Sounds like you are having trouble correctly displaying your elements using Grid, and have gotten around this by the hack of pushing everything through GraphicsGrid instead. You should work on getting it to work properly in Grid. You could post a question with the problems you where facing there. –  jVincent Jan 30 '13 at 12:52
    
@jVincent, I tried to place the list containing the control objects such as popupmenu, input boxes in a grid. But the problem here is that I have to set the individual Itemsize of the control object.Can I set the ImageSize of the Grid? –  Anuk Feb 21 '13 at 16:02
    
@Anuk You could use scaled itemsizes and wrap the grid in a pane that has a fixed imagesize eg. Pane[Grid[{{1, 2}, {3, 4}}, ItemSize -> Scaled[0.5]], ImageSize -> 200] –  jVincent Feb 21 '13 at 23:10
    
@jVincent, even the ItemSize works, the control objects are not displayed properly at all times for different dimensions. Is there a magical number that scales to actual ImageSize of the control object that we specify? –  Anuk Feb 22 '13 at 4:55
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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