为什么标签的顺序是;“向后”;在matlab图形中的JPanel中的Java组件上进行Tab时?

为什么标签的顺序是;“向后”;在matlab图形中的JPanel中的Java组件上进行Tab时?,java,matlab,focus,traversal,Java,Matlab,Focus,Traversal,通过运行这个matlab代码示例并在组件之间切换,您可以看到如何在matlab图形上遍历Java组件(添加了 javacomponent)的行为不符合预期。请,如果有人对如何使选项卡顺序正常运行有任何见解,我将不胜感激:) 我以前也见过这个。。。答案就在这里:why(70)有一个matlab内置函数可以帮助解决这个问题。请尝试uistack,有关文档,请参阅。 function hfig = testJavaFocus % Illustration of tab-order focus prob

通过运行这个matlab代码示例并在组件之间切换,您可以看到如何在matlab图形上遍历Java组件(添加了 javacomponent)的行为不符合预期。请,如果有人对如何使选项卡顺序正常运行有任何见解,我将不胜感激:)


我以前也见过这个。。。答案就在这里:
why(70)
有一个matlab内置函数可以帮助解决这个问题。请尝试
uistack
,有关文档,请参阅。
function hfig = testJavaFocus
% Illustration of tab-order focus problem.
% Run this and start hitting tab. Observe that tab-order goes "backwards"
% when traversing through the components in the JPanel. WHY!!!??!?!?!?

hfig = figure;
components = [];

%% Add JTextField
text = javaObjectEDT('javax.swing.JTextField',6);
text.setFocusable(true);
components{end+1} = text;

%% Add JTextField
text = javaObjectEDT('javax.swing.JTextField',6);
text.setFocusable(true);
components{end+1} = text;

%% Add JPanel - we will add 3 components to this panel to illustrate focus problem
panel = javaObjectEDT('javax.swing.JPanel');
panel.setBackground(java.awt.Color.GREEN);

text = javaObjectEDT('javax.swing.JTextField',6);
text.setFocusable(true);
panel.add(text);
text = javaObjectEDT('javax.swing.JTextField',6);
text.setFocusable(true);
panel.add(text);
text = javaObjectEDT('javax.swing.JTextField',6);
text.setFocusable(true);
panel.add(text);

components{end+1} = panel;

%% Add JTextField
text = javaObjectEDT('javax.swing.JTextField',6);
text.setFocusable(true);
components{end+1} = text;

%% Add JTextField
text = javaObjectEDT('javax.swing.JTextField',6);
text.setFocusable(true);
components{end+1} = text;

%% Add all components to the figure via javacomponent()
x = 10;
padding = 3;
for i = 1:length(components)
   prefDim = components{i}.getPreferredSize();
   widpos = [x,10,prefDim.width,prefDim.height];
   [jh, hg] = javacomponent(components{i},widpos,hfig);
   x = x + prefDim.width + padding;
end

end