Actually arrays of objects are fine, I had mistakenly populated the array with a copy of the same object handle rather than deep copies.
Property Inspector for custom classes
6 views (last 30 days)
Show older comments
I'd like to use Property Inspector to be able to edit custom classes. From what I can see, this works (i.e., I can type "inspect(obj)" and edit properties) as long as the classes are handle classes, but it doesn't seem as effective as for some built-in classes. For example:
- If I look at Figure of Axes objects in Property Inspector, properties are listed in groups. This doesn't occur for my custom classes even if I inherit matlab.mixin.CustomDisplay and implement getPropertyGroups (which enables grouping of properties in the command window display of a class).
- Editors are sensible for integers, logicals etc. Figures etc have nice specialised editors for colours, fonts, etc. Is there any way that I can reuse those?
I've attached a picture showing an example of what I'm meaning for the plot line inspector--showing the sections (e.g. "Color and Styling", "Markers", etc) for the different properties, and the special editor used for the line colour.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1821090/image.jpeg)
3 Comments
Accepted Answer
Kanishk
on 18 Dec 2024
Hi @.json
I understand you want to group properties in the Property Inspector and require a way to have rich editors for colors, fonts and more. Analyzing the documentation and code available for the Property inspector, I get that some features of the Property Inspector are specifically designed to cater the graphics objects which provides features like grouping and rich editors.
To get editors for color and font, a simple app in appdesigner can be designed with "uicolorpicker" and "uisetfont". To demonstrate, I have made simple class and placed a very naive condition in the app to check if the field requires the color picker. I have attached the app the in the answer and here is the code for the custom class.
classdef MyCustomClass < handle
properties
Property1
Property2
Color(3,1) double
isvalid logical
end
methods
function obj = MyCustomClass(prop1, prop2)
obj.Property1 = prop1;
obj.Property2 = prop2;
obj.Color = [0 1 1];
obj.isvalid = true;
end
end
methods(Static)
function y = add
y = obj.Property1+obj.Property2;
end
end
end
To run the app with a class object,
>> obj = MyCustomClass(10,20);
>> inspectApp(obj)
This launches the following app:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1821311/image.png)
For grouping Properties, I was not able to come with a simple solution. One idea is to design groupings of properties in HTML and using "uihtml" to show in the app designer.
I also found some MATLAB File Exchange submissions which might be of help.
- https://www.mathworks.com/matlabcentral/fileexchange/28732-property-grid-using-jide-implementation
- https://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methods-properties-callbacks-of-an-object
Happy Coding!
More Answers (0)
See Also
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!