[英]How to send data from a JTextField to a JList?
I have integrated a form to store the data from a JTextField
to a variable after a user enters something and presses a JButton
. 我已经集成了一个表单,用于在用户输入内容并按下
JButton
之后将数据从JTextField
存储到变量。 My issue is that I want to send this data to a JList
every time they type something in and hit the submit button. 我的问题是,每次他们输入内容并单击“提交”按钮时,我都希望将此数据发送到
JList
。
How is this possible? 这怎么可能?
Add an ActionListener to the instance of the JButton, get the content of the JTextField (say with name aTextField), and store it to a list (say you have a class member JList dataInputted ) 将ActionListener添加到JButton的实例,获取JTextField的内容(例如,名称为aTextField),并将其存储到列表中(例如,您具有类成员JList dataInputted )
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
// Execute when button is pressed
dataInputted.addElement(aTextField.getText());
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.