File Exchange

image thumbnail

Manage and Dock Figures into Group

version 1.5 (3.87 KB) by

SETFIGDOCKED docks figures at specified positions in group of figures

4 Downloads

Updated

View License

group = setfigdocked('PropertyName1',value1,'PropertyName2',value2,...)
  PropertyName:
      - GroupName name of group need to be generated
      - GridSize scalar or vector quantity, defines number of rows
                    and columns of cell in group
      - SpanCell vector or matrix quantity, size n x 4,
                    [row col occupiedrows occupiedcols]
                    build an cell at the position (row, col) in group
                    cell (GridSize) which occupies "occupiedrows"
                    rows and "occupiedcols" columns
      - Figure handle of figure
      - Figindex index position of figure in group cell
      - Maximize 0/1, maximize group
      - GroupDocked 0/1, dock group

Example:
         group = setfigdocked('GroupName','Image and Edges','GridSize',3,'SpanCell',[1 2 2 2]);
         im1 = imread('cameraman.tif');
         figure;imshow(im1);set(gcf,'Name','Cameraman','NumberTitle','off')
         group = setfigdocked('GroupName','Image and Edges','Figure',gcf,'Figindex',2);
 
         figure; edge(im1,'prewitt');set(gcf,'Name','Prewitt method','NumberTitle','off')
         group = setfigdocked('GroupName','Image and Edges','Figure',gcf,'Figindex',1);
 
         figure; edge(im1,'roberts');set(gcf,'Name','Roberts method','NumberTitle','off')
         group = setfigdocked('GroupName','Image and Edges','Figure',gcf,'Figindex',3);

         figure; edge(im1,'roberts');set(gcf,'Name','Roberts method','NumberTitle','off')
         group = setfigdocked('GroupName','Image and Edges','Figure',gcf,'Figindex',4);

         figure; edge(im1,'roberts');set(gcf,'Name','Roberts method','NumberTitle','off')
         group = setfigdocked('GroupName','Image and Edges','Figure',gcf,'Figindex',5);

         figure; edge(im1,'canny');set(gcf,'Name','Canny Method','NumberTitle','off')
         group = setfigdocked('GroupName','Image and Edges','Figure',gcf,'Figindex',6);

         group = setfigdocked('GroupName','Image and Edges','Maximize',1,'GroupDocked',0);

Comments and Ratings (8)

Thank you great contribution. However, i encounter some errors when running. The requested figures are indeed grouped in a single window, but the following error occurs:

setFigDockGroup: Error using set
The name 'userdata' is not an accessible property for an instance of class
'com.mathworks.widgets.desk.DTDocumentContainer'.

Error in setFigDockGroup (line 192)
          set(hContainer,'userdata',group);

Additionally, is it possible to automatically undock the window from the matlab? So keep figures docked to a window, but not have the window itself docked to matlab?

Thierry Dalon

If the figure was already docked in the Group it is not enough to select the destination tile to dock the figure to a selected position. Somehow the previous position is remembered.
As workaround reset the dock group of the figure to a hidden 'Temp' group to clear the memory of the position - before docking the figure.

Pete

Pete (view profile)

One important thing to note: This script relies on a bit of a hack where some key strokes are simulated to set focus on the dock.

If, earlier in your script, you have used something like Psychtoolbox's 'ListenChar' to intercept keystrokes, then setfigdocked will not function properly. Just a friendly warning! (5 hours of debugging, and several white hairs, later..)

Still a good function though!

Pete

Pete (view profile)

I was looking to make a GUI for a toolbox, involving multiple figure windows. This struck me as an elegant alternative to trying to manually keep multiple figures arranged.

Seems to work very nicely. (R2012b; Win7-64bit)

Keith

Keith (view profile)

This works fine when I run it from the command window, but when I try to run it from inside a GUI, I'm getting an error. Here's the trace:

Attempt to reference field of non-structure array.

Error in setfigdocked (line 169)
            jpanel.requestFocus(true); % Focus on Dock

Error in particletracking>splittifbutton_Callback (line 790)
group = setfigdocked('GroupName','Images2','GridSize',[2 3], 'GroupDocked', 0);

Error in gui_mainfcn (line 96)
        feval(varargin{:});

Error in particletracking (line 42)
    gui_mainfcn(gui_State, varargin{:});

Error in @(hObject,eventdata)particletracking('splittifbutton_Callback',hObject,eventdata,guidata(hObject))

 
Error while evaluating uicontrol Callback

Yair Altman

Yair Altman (view profile)

take at look at the related utility setFigDockGroup - http://www.mathworks.com/matlabcentral/fileexchange/16650-setfigdockgroup

Pirmin Borer

Really good tool. I also tried for a while how to set up groups with the DTgroup class, it takes a while to understand matlabs built-in java. So thanks very much!!!!

Sebastian Hölz

SWEET !!!
Great job. I've been searching the Matlab Java Archives for the appropriate objects/methods/properties for (almost) years and just could not find them. The docking of figures into seperate containers is a great way to organize your work-flow, if you have lots of figures to work with at the same time and don't want to get lost. I'll highly recommend to look into this ...

Updates

1.5

fix error caused by empty jpanel

1.4

Fixed error on Matlab 2011, and allow multiple figures docking in the same cell.

1.3

Fix errors on Matlab v2009 and later releases

1.1

Fix errors which occur MATLAB v.2009 and later release

MATLAB Release
MATLAB 7.1.0 (R14SP3)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video