[英]Can I have a textfield inside a label?
What I would like to do is display the following in a form:我想做的是以表格形式显示以下内容:
Open [15] minutes before class
Where [15]
is a text-field.其中
[15]
是文本字段。 Is this possible?这可能吗?
Use a 'composite component' by adding the required parts to a JPanel
.通过将所需部分添加到
JPanel
来使用“复合组件”。 EG例如
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);
}
});
}
}
Note that I swapped the 'textfield' for a JSpinner
- a more suitable component for selecting 'time in minutes'.请注意,我将“文本字段”换成了
JSpinner
- 一个更适合选择“以分钟为单位的时间”的组件。
Can I have a textfield inside a label?
answer is, yes you can, this is basic property of Java AWT / Swing
Objects答案是,可以,这是 Java
AWT / Swing
对象的基本属性
JComboBox
, JTable
, JList
, JSpinner
, JFile(Color)Chooser
.... are compound JComponents
, you can extract all JComponent
and put that together again. JComboBox
、 JTable
、 JList
、 JSpinner
、 JFile(Color)Chooser
.... 是复合JComponents
,您可以提取所有JComponent
并将其再次组合在一起。
you can put any of JComponents
to the another你可以把任何一个
JComponents
放到另一个
only JFrame/JDialog/JWindow
and JPanel
have got implemented LayoutManager
by default in the API, for rest of then you have to implements proper LayoutManager只有
JFrame/JDialog/JWindow
和JPanel
在 API 中默认实现了LayoutManager
, 对于 rest 那么你必须实现适当的 LayoutManager
I think I have not understood.我想我还没有明白。 But, I'll try:
但是,我会尝试:
You can get the text from a TextField:您可以从 TextField 中获取文本:
label.setText("Open " + textField.getText()+ " minutes before class"); label.setText("打开" + textField.getText()+ "课前分钟");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.