No BSD License  

Highlights from
Yet Another Layout Manager

  • resize_example 1. This layout manager is based on MATLAB Central File Exchange entry "Resizable
  • RE_Axis custom axis
  • RE_Box elementary layout building block, positions matrix of elements
  • RE_Button checkboxes/radiobuttons/togglebuttons column
  • RE_Layout Class which defines figure and has many factory methods for ui components
  • RE_Panel custom axis
  • RE_Separator separator with or without label
  • RE_Tabpane tab pane implementation using java element
  • View all files
image thumbnail
from Yet Another Layout Manager by amilcar chaudhary
Easily align gui elements and quickly build resizable gui

RE_Tabpane
%% tab pane implementation using java element
classdef RE_Tabpane < RE_Box
    
    properties
        YOffset = 30;
        Pane = [];
        Tabs = [];
        JComp = [];
        Value = 1;
        TabpaneFcn = [];        
    end

    methods

        % CONSTRUCTOR
        function obj = RE_Tabpane(varargin)

            obj = obj@RE_Box(); set(obj, varargin{:});
            hui = uipanel('units', 'pixels', 'FontWeight', 'bold', 'Fontname', 'verdana', 'bordertype', 'line', 'borderwidth', 1, 'HighlightColor', [.5,.5,.5]);
            
            % tab definition
            jcomp = javax.swing.JTabbedPane();
            jcomp.setFocusable( false );

            [jcomp, htab] = javacomponent( jcomp, [], hui );
            
            pane = RE_Box({htab; []});
            set( pane, 'Height', [obj.YOffset, -1] );
            set(obj, 'Element', hui, 'Pane', pane, 'JComp', jcomp);            
        end
        
        function add(obj, varargin)
            
            for i = 1:length(varargin)/2
                
                tabs(i).name = sprintf( '  %s   ', varargin{2*i-1});
                tabs(i).pane  = varargin{2*i};
                
                jlabel = javax.swing.JLabel();
                jlabel.setName( tabs(i).name );
                obj.JComp.add( jlabel );
                
             	set(tabs(i).pane.Children, 'Parent', obj.Handle);
                set( tabs(i).pane, 'Position', [-1000, -1000, 100, 100] );
            end
            
            obj.Tabs = tabs;
            set( obj.JComp, 'StateChangedCallback', @(varargin) StateChangeFcn(obj) );
            
            obj.JComp.setSelectedIndex(obj.Value-1);
        end
    end % methods

    methods (Access = protected)
        
        %% set elements position
        function setPosition(obj)

            % uipanel
            pd = obj.Padding;
            pos = obj.Position(:) + [pd(1); pd(2); -pd(1)-pd(3)-3; -pd(2)-pd(4)];
            pos([3,4]) = max(2, pos([3,4])-3);
            set(obj.Handle(1), 'Position', pos);

            % java tabs
            pos([1,2]) = 0;
            pos(3) = pos(3)+3;
            set(obj.Pane, 'Position', pos);
        end
    end % methods
end % classdef

%% tab changed callback
function StateChangeFcn(obj)

set(obj.Pane.Element{2}, 'Position', [-1000, -1000, 100, 100]);

old = obj.Value;
ind = obj.JComp.getSelectedIndex + 1;

obj.Value = ind;
obj.Pane.Element{2} = obj.Tabs(ind).pane;

if isempty(obj.Position), return; end
set(obj.Pane, 'Position', get(obj.Pane, 'Position'));

if isempty(obj.TabpaneFcn) || old == ind, return; end
obj.TabpaneFcn([], struct('value', ind, 'oldvalue', old));
end

Contact us at files@mathworks.com