Tag: jtextfield

JTextField自动完成错误

在这个post中 ,我找到了一种在JTextField (和JComboBox实现AutoCompletefunction的方法,但没有问题。 尝试在JTextField实现此function时,它会抛出一些exception。 以下代码将演示此问题。 它非常简单,与我使用JComboBox的方式很相似,它工作得很好。 有人可以帮我找到解决方案。 这是代码: ( 请注意我使用的是swingx ) import javax.swing.JList; import org.jdesktop.swingx.JXFrame; import org.jdesktop.swingx.JXTextField; import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator; public class ErrorDemo { public static void main(String[] args) { JXFrame frame = new JXFrame(“Error Demo”); JXTextField field = new JXTextField(); String[] users = {“aaa”, “bbb”, “ccc”}; AutoCompleteDecorator.decorate(new JList(users), field); frame.getContentPane().add(field); frame.pack(); frame.setLocationByPlatform(true); frame.setDefaultCloseOperation(JXFrame.EXIT_ON_CLOSE); frame.setVisible(true); } […]

如何获得彩色线来区分文本字段数组

我开发了一个框架,我使用GridBagLayout来安排12X12的文本字段。 即框架上共有144个文本字段。 现在我想在每个3列和3行之后用彩色线区分这些文本字段,如下图所示。 我试过很多方面,但我找不到解决办法。 请建议。 下面是我的代码的一部分。 提前致谢。 1 2 3 | 4 5 6 | 7 8 9 | 10 11 12 | | | 1 2 3 | 4 5 6 | 7 8 9 | 10 11 12 | | | 1 2 3 | 4 5 6 | 7 8 9 | […]

在JTextField中键入阿拉伯数字

我试图在JTextField键入阿拉伯数字,我使用DocumentListener ,如下所示: txtName.getDocument().addDocumentListener(this); … public void insertUpdate(DocumentEvent e){setLabel();} public void removeUpdate(DocumentEvent e){setLabel();} public void changedUpdate(DocumentEvent e){} public void setLabel() { String s = txtName.getText(); s = s.replace(‘0′,’\u0660’); s = s.replace(‘1′,’\u0661’); s = s.replace(‘2′,’\u0662’); s = s.replace(‘3′,’\u0663’); s = s.replace(‘4′,’\u0664’); s = s.replace(‘5′,’\u0665’); s = s.replace(‘6′,’\u0666’); s = s.replace(‘7′,’\u0667’); s = s.replace(‘8′,’\u0668’); s = s.replace(‘9′,’\u0669’); s […]

焦点获得和焦点失去的事件

我的java swing表单中有4个JTextfields。 问题是我需要通过Java代码将Focus从一个JTextField移动到另一个JTextField而不是使用tab键。 如果JTextField2获得的Focus意味着需要选择JTextField2中的内容。 我不知道怎么做这个plz把你正确的代码与这个问题联系起来

如何将JTextField从JFrame传递到另一个JFrame

当我在JFrame1的JTextField中输入名字,姓氏和其他信息,然后单击下一步按钮时,输入的数据将显示最后一个JFrame上的所有输入数据。 示例:这是动画gif,最后一帧是我想要的,因为我仍然不知道如何制作它: 我怎样才能做到这一点? 如果这是一个新手问题,我很抱歉,但我正在学习.. 我正在使用NetBeans GUI构建器。 编辑:如果我正确的话,我创造了这样的idk …… public class User { private String username; private String password; public User() { username = null; password = null; } public User getUser() { User user = new User(); username = TexUsername.getText(); return user; } } 在我的DisplayFrame中,我不知道里面放了什么 public void setUser(User user) { // idk what to put […]

从给定的Form中提取值

我想在单击按钮save提取值。 从JTextField和JTable行和列中提取值。 只是想大致了解如何提取和保存不同变量中的值。 我想在按钮保存下执行这些保存操作。 package build; import java.awt.*; import javax.swing.*; import com.jgoodies.forms.layout.FormLayout; import com.jgoodies.forms.layout.ColumnSpec; import com.jgoodies.forms.layout.RowSpec; import com.jgoodies.forms.factories.FormFactory; import javax.swing.table.DefaultTableModel; import javax.swing.border.TitledBorder; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class Table_Edit { private JTextField textField; private JTable table; private String Table_Name = new String(); public Table_Edit() { JFrame frame = new JFrame(“Table”); frame.setSize(600, 400); frame.getContentPane().setLayout(new FormLayout(new ColumnSpec[]{ […]

如何在创建后在JTextField中设置新文本?

我有一个jTextField,我在创建框架时将它的值设置为一定的总和。 这是启动代码: totalTextField.setText( itemsPriceTextField.getText() + Float.toString(orderDetails.delivery) ); 此文本字段应显示用户选择的项目总和。 选择在不同的帧上完成,并且两个帧一次可见/不可见。 用户可以来回移动并添加/删除项目。 现在,每次我再次设置此框架时,我需要将值集重新加载到该字段 (也许没有做出任何改变,但如果是这样,我需要设置新的正确总和)。 我非常绝望。 任何人都可以给我一个线索吗? 提前致谢! 🙂

JTextArea JLabel比较两个txt。 文件逐行

每一个人。 我通过显示在同一区域完成了我的代码两个txt文件。 但我想逐行比较两个txt文件。 我想用彩色线条来表示差异,最后,不同的字母或单词,我要大胆。 我怎么开始? 谢谢,我的代码在这里。

使用JButton将文本添加到两个文本字段

如果我的问题不是很具体,那么我正在努力做到这一点。 我有一个计算器,有两个JTextFields,一个JLabel(“Answer =”)和一个JTextField作为答案。 我有一个JButtons(0到9)数组,允许用户点击它们将数字添加到JTextField,光标在其中激活…这是问题所在。 我只能将两个文本字段中的一个添加到它们中,或者两者都添加相同的数字。 例如,如果我单击一个按钮并且addActionListener设置为(new AddDigitsONE) ,它将只允许我向第一个JTextField添加数字。 即使在我尝试将光标设置为第二个JTextField并使用JButtons为其添加数字之后,它也会跳回到第一个JTextField。 用于将JButtons数组添加到JFrame中的JPanel的代码 // input is my JPanel set to BorderLayout.SOUTH for (int i = 0; i < button.length; i++) { text = Integer.toString(i); button[i] = new JButton(); button[i].setText(text); input.add(button[i]); button[i].addActionListener(new AddDigitsONE()); } 我的动作监听器的代码:第一个JTextField // firstNumber is my first JTextField // command is the button pressed (0-9) // […]

如何调整JTextField的大小?

如何调整JTextField的大小?