我可以在标签内放置文本字段吗? [英] Can I have a textfield inside a label?

查看:168
本文介绍了我可以在标签内放置文本字段吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是在表单中显示以下内容:

What I would like to do is display the following in a form:

Open [15] minutes before class

其中 [15] 文字-field。这可能吗?

推荐答案

通过将所需部件添加到<使用'复合部件' code>的JPanel 。 EG

Use a 'composite component' by adding the required parts to a JPanel. E.G.

import java.awt.FlowLayout;
import javax.swing.*;

class TimeBeforeClass {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JPanel gui = new JPanel(new FlowLayout(FlowLayout.LEFT, 3,3));
                gui.add(new JLabel("Open"));
                gui.add(new JSpinner(new SpinnerNumberModel(15,0,20,1)));
                gui.add(new JLabel("minutes before class"));
                JOptionPane.showMessageDialog(null, gui);
            }
        });
    }
}

请注意,我将'textfield'换成了 JSpinner - 更适合选择以分钟为单位的时间的组件。

Note that I swapped the 'textfield' for a JSpinner - a more suitable component for selecting 'time in minutes'.

这篇关于我可以在标签内放置文本字段吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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