本文介绍了"将"文本的JTextField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图做一个小的应用程序,其中U输入ID(以JButton的 - 从0到9的帮助 - ),然后通过已pssed到putText法$ P $,然后在JTextField中显示它的数量-the问题是,我每次preSS新号码一个我$ p $在前看不见前pssed:秒。谁能帮我与PLS?
公共类IdPanel继承JPanel { 私人的JTextField idField;
私人的JLabel idLabel; 公共IdPanel(){ 的setLayout(新的GridBagLayout()); 集preferredSize(新尺寸(500,70)); idField =新的JTextField(20);
idField.setFont(新字体(衬线,Font.PLAIN,20)); idLabel =新的JLabel(输入ID:);
idLabel.setFont(新字体(衬线,Font.PLAIN,20)); GridBagConstraints的GC =新的GridBagConstraints(); gc.gridx = 0;
gc.gridy = 0;
gc.insets =新插图(9,9,9,9);
gc.anchor = GridBagConstraints.CENTER;
加(idLabel,GC); gc.gridx = 1;
gc.anchor = GridBagConstraints.CENTER;
加(idField,GC);
} 公共无效putText(串号){
idField.setText(数);
}
}
解决方案
尝试:
idField.setText(idField.getText()+电话号码);
I'm trying to make a small application where U input ID (with help of JButton -from 0 to 9 - ) and then pass the number that have been pressed to putText-Method and then display it in JTextField-the problem is that every time I press new number the one I pressed before disapears:s . Could anyone help me with that pls?
public class IdPanel extends JPanel {
private JTextField idField;
private JLabel idLabel;
public IdPanel() {
setLayout(new GridBagLayout());
setPreferredSize(new Dimension(500, 70));
idField = new JTextField(20);
idField.setFont(new Font("Serif", Font.PLAIN, 20));
idLabel = new JLabel("Enter ID:");
idLabel.setFont(new Font("Serif", Font.PLAIN, 20));
GridBagConstraints gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 0;
gc.insets = new Insets(9, 9, 9, 9);
gc.anchor = GridBagConstraints.CENTER;
add(idLabel, gc);
gc.gridx = 1;
gc.anchor = GridBagConstraints.CENTER;
add(idField, gc);
}
public void putText(String number) {
idField.setText(number);
}
}
解决方案
try:
idField.setText(idField.getText()+number);
这篇关于"将"文本的JTextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!