【源码】findjobj函数——查找Matlab图形对象的Java句柄

在这里插入图片描述

查找Java容器或Matlab GUI句柄中包含的所有Java对象

Find all java objects contained within a java container or Matlab GUI handle

如果没有指定输出参数,那么将显示一个交互式GUI窗口,其中包含所有容器组件、属性和回调的树视图。

If no output parameter is specified, then an interactive GUI window will be displayed with a tree-view of all container components, their properties and callbacks.

本函数的使用语法:

[handles,levels,parentIds,listing] = findjobj(container,‘PropName’,PropValue(s),…)

输入:

Inputs:

  • container:可选的GUI句柄,如果没有指定,则使用当前图形界面。

  • container - optional GUI handle. If unsupplied then current figure will be used

  • ‘PropName’,PropValue:不区分大小写属性对的可选列表。

  • ‘PropName’,PropValue - optional list of case insensitive property pairs. PropName may also be named -PropName.

Supported properties:

  • ‘position’ - filter results based on those elements that contain the specified X,Y position or a java element

Note: specify a Matlab position (X,Y = pixels from bottom left corner), not a java one

  • ‘size’ - filter results based on those elements that have the specified W,H (in pixels)

  • ‘class’ - filter results based on those elements that contain the substring (or java class) PropValue

Note: filtering is case insensitive and relies on regexp, so you can pass wildcards etc.

  • ‘property’ - filter results based on elements that possess the specified case-insensitive property string or have property values in cell array format: {‘propName’, ‘propValue’}. Example: findjobj(…,‘property’, {‘Text’,‘click me’})

  • ‘depth’ - filter results based on specified depth. 0=top-level, Inf=all levels (default=Inf)

  • ‘flat’ - same as: ‘depth’,0

  • ‘not’ - negates the following filter: ‘not’,‘class’,‘c’ returns all elements EXCEPT those with class ‘c’

  • ‘persist’ - persist figure components information, allowing much faster results for subsequent invocations

  • ‘print’ - display all java elements in a hierarchical list

Note1: optional PropValue of element index or handle to java container

Note2: normally this option would be placed last, after all filtering is complete.

  • ‘list’ - same as ‘print’

输出:

Outputs:

  • handles:Java元素句柄列表

  • handles - list of handles to java elements

  • levels:Java元素的对应层次结构列表(top=0)

  • levels - list of corresponding hierarchy level of the java elements (top=0)

  • parentIds:对应Java元素父容器的索引列表(未经过滤的句柄)

  • parentIds - list of indexes (in unfiltered handles) of the parent container of the corresponding java element

  • listing:“print”/“list”选项的结果(如果未指定“print”/“list”,则为空)

  • listing - results of ‘print’/‘list’ options (empty if ‘print’/‘list’ were unspecified)

使用举例:

hButton = uicontrol(‘string’,‘click me’);

jButton = findjobj(hButton,‘nomenu’); % or: jButton = findjobj(‘property’,{‘Text’,‘click me’});

jButton.setFlyOverAppearance(1);

jButton.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.HAND_CURSOR));

set(jButton,‘FocusGainedCallback’,@myMatlabFunction); % some 30 callback points available…

jButton.get; % list all changeable properties…

hEditbox = uicontrol(‘style’,edit’);

jEditbox = findjobj(hEditbox,‘nomenu’);

jEditbox.setCaretColor(java.awt.Color.red);

jEditbox.KeyTypedCallback = @myCallbackFunc; % many more callbacks where this came from…

jEdit.requestFocus;

(Many more examples in the utility’s help section)

需要注意的问题:

无法处理多个容器对象,一次只能处理一个

  • Cannot currently process multiple container objects - just one at a time

当图形中包含许多UI组件时,初始处理速度会稍慢(因此最好使用“persist”)

  • Initial processing is a bit slow when the figure is laden with many UI components (so better use ‘persist’)

目前按照位置+大小查找传递容器的Matlab句柄:应该可以找到更好的方法来实现

  • Passing a container Matlab handle is currently found by position+size: should find a better way to do this

标签在Java中只有一个只写文本属性,所以不能使用“属性”、“文本”、“字符串”来表示

  • Labels have a write-only text property in java, so can’t be found using ‘property’,{‘Text’,‘string’} notation

参考技术文档的相关网页:

完整源码下载地址:

http://page2.dfpan.com/fs/6lcj4221229156d8d92/

更多精彩文章请关注微信号:在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42825609/article/details/86568679