按TAB键到“垂直轴"组件中的下一个Java [英] Press TAB to next Java in Vertical axis component

查看:109
本文介绍了按TAB键到“垂直轴"组件中的下一个Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个面板为null的布局,并具有以下代码

I have a panel null layout and have the following code

int k=130;
int h=10;
for (int i=0; i<22; ++i) {
    jTextFieldArray[i] = new JTextField();
    jTextFieldArray[i].setBounds(k, h, 120, 25);
    String s = Integer.toString(i+1);
    jTextFieldArray[i].setText(s);
    h+=30;
    panel.add(jTextFieldArray[i]);  
    if (i==10) k=430; 
    if (i==10) h=10;
}

当我按TAB键时,光标将移动到下一个水平Textfield.如何使其移动或指向下一个水平Textfield

When I press TAB, the cursor will move to the next horizontal Textfield. How can I make it moving or pointing to the next horizontal Textfield

推荐答案

如果我对问题的解释是正确的,那么您希望自定义焦点遍历.您可以提供自己的焦点遍历策略以覆盖默认的焦点循环顺序.看看中的自定义焦点遍历主题>如何使用Focus Subsystem 教程.它有一个示例,说明如何安装自定义策略.

If my interpretation of the question is correct you would like to customize the focus traversal. You can provide your own focus traversal policy to override default focus cycling order. Take a look at Customizing Focus Traversal topic in How to Use the Focus Subsystem tutorial. It has an example that illustrates how to install a custom policy.

在旁注中,正如注释中已经提到的,绝对定位(空布局)有很多缺点,应格外小心.在大多数情况下应该/可以避免空布局.如不使用布局管理器(绝对定位)所述:

On a side note, as already mentioned in comments, absolute positioning (null layout) has many drawbacks and should be considered with extra care. Null layouts should/can be avoided in most cases. As stated in Doing Without a Layout Manager (Absolute Positioning):

尽管没有布局管理器也是可以的,但是您应该使用 布局管理器(如果可能).布局管理器使工作更轻松 调整以适应外观相关的组件外观 不同的字体大小,容器不断变化的大小以及不同的字体 语言环境.布局管理器也可以很容易地被其他人重用 容器以及其他程序.

Although it is possible to do without a layout manager, you should use a layout manager if at all possible. A layout manager makes it easier to adjust to look-and-feel-dependent component appearances, to different font sizes, to a container's changing size, and to different locales. Layout managers also can be reused easily by other containers, as well as other programs.

看看布局管理器的可视指南熟悉Swing布局.

Take a look at A Visual Guide to Layout Managers to get familiar with Swing layouts.

这篇关于按TAB键到“垂直轴"组件中的下一个Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆