Why is the tab-order "backwards" when tabbing over Java components inside a JPanel?
4 次查看(过去 30 天)
显示 更早的评论
function 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
0 个评论
回答(1 个)
the cyclist
2013-8-7
I don't know much about MATLAB GUIs, much less Java-based ones, but maybe this page will shed some light?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!