我可以在标签中添加文本字段吗? [英] Can I have a textfield inside a label?

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

问题描述

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

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

Open [15] minutes before class

其中[15] 是一个文本字段.这可能吗?

Where [15] is a text-field. Is this possible?

推荐答案

通过将所需部件添加到 JPanel 来使用复合组件".E.G.

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);
            }
        });
    }
}

请注意,我将文本字段"替换为 JSpinner - 一个更适合选择时间以分钟为单位"的组件.

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

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

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