Class properties do not have values in uibutton callback
古いコメントを表示
I have a uifigure and components in a class. I save 2 button handles as properties of the class: dockerButton and exitButton. When I click the dockerButton, the obj class I pass into its callback has an empty exitButton. When I click the exitButton, the obj class passed into its callback has both exitButton and dockerButton populated properly. I want this behavior for when I click the dockerButton; I want to be able to manipulate the exitButton that is a property of the obj instance passed in. What am I doing wrong?
When I click the dockerButton, it goes into dockView and my obj class is:
exitButton: [] <<-- I want this to have the handle to the exitButton!!
parent: [1×1 GridLayout]
borderPane: [1×1 Panel]
grid: []
title: 'GEO'
uuid: [1×1 java.lang.String]
cmapDir: [1×1 CmapDir]
dockerButton: [1×1 Button]
dockFile: 'arrow-collapse_16.png'
undockFile: 'arrow-expand_16.png'
When I click the exitButton, closeView gives me:
exitButton: [1×1 Button] <<-- I get both here!!
parent: [1×1 GridLayout]
borderPane: [1×1 Panel]
grid: []
title: 'GEO'
uuid: [1×1 java.lang.String]
cmapDir: [1×1 CmapDir]
dockerButton: [1×1 Button] <<-- so it's not a callback idiosyncracy
dockFile: 'arrow-collapse_16.png'
undockFile: 'arrow-expand_16.png'
classdef BaseView
properties
exitButton
parent
borderPane
grid
title
uuid
cmapDir
dockerButton
dockFile
undockFile
end % properties
methods
%% Constructor
function obj = BaseView(parent, title, cmapDir)
% parent is the grid from NextGenWorkspace
obj.parent = parent;
obj.title = title;
obj.cmapDir = cmapDir;
randomUUID = java.util.UUID.randomUUID;
obj.uuid = randomUUID.toString;
% start with a panel so I can get a nice outline. NOTE that
% even though HighlightColor is a property of uipanel, it only
% works when the parent is a figure (not a uifigure)
obj.borderPane = uipanel(obj.parent, ...
'BorderType', 'line', ...
'UserData', obj.uuid, ...
'Tag', title); %, ...
%'HighlightColor', [1 0 0]);
% 2 rows, 1 col
mainGrid = uigridlayout(obj.borderPane, ...
'tag', 'mainGrid');
mainGrid.RowHeight = {50,'1x'};
mainGrid.ColumnWidth= {'1x'};
% create header with title and close button
header = uipanel(mainGrid, ...
'BorderType', 'line', ...
'tag', 'header');
% 1 row, 2 col
hdrGrid = uigridlayout(header, ...
'tag', 'hdrGrid'); %, ...
% 'BackgroundColor',[0.7 0.7 0.7]);
hdrGrid.RowHeight = {33};
hdrGrid.ColumnWidth= {'1x',33,33};
uilabel(hdrGrid,'text',title);
% save icons that potenially can be used repeatedly
obj.dockFile = fullfile(pwd,'resources','arrow-collapse_16.png');
obj.undockFile = fullfile(pwd,'resources','arrow-expand_16.png');
windowCloseFile = fullfile(pwd,'resources','window-close_16.png');
% create dock button
if exist(obj.undockFile,'file') == 0
obj.dockerButton = uibutton(hdrGrid,'Text','>>');
else
obj.dockerButton = uibutton(hdrGrid, ...
'icon', obj.undockFile, ...
'text','');
end
set(obj.dockerButton, 'Tooltip', 'Undock View', ...
'userdata', 'docked=true', ...
'ButtonPushedFcn', @(src,event) dockView (obj,src,event));
% create close button
if exist(windowCloseFile,'file') == 0
obj.exitButton = uibutton(hdrGrid,'text','X');
else
obj.exitButton = uibutton(hdrGrid,'text','', ...
'icon', windowCloseFile);
end
set(obj.exitButton, 'Tooltip', 'Remove View', ...
'ButtonPushedFcn', @(src,event) closeView (obj,src,event));
% now the main workspace area where sub classes will put
% widget
obj.grid = uigridlayout(mainGrid, ...
'tag', 'grid');
obj.grid.RowHeight = {'1x'};
obj.grid.ColumnWidth= {'1x'};
end % function
end % methods
methods (Access = protected)
% callback for the close button
function closeView(obj, ~, ~)
disp ('BaseView::closeView');
end
% pop out the view into its own dialog or return it to its tab
function dockView(obj, ~, ~)
disp ('BaseView::dockView');
end
end % dockView
end % methods
end % classdef
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Desktop についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!