Send Textfield Data to ListView in Java

0
46

This tutorial entitle ” Send Textfield Data to ListView using Java ” will teach you on how the values of jTextfield send/add data to jList using Netbeans. jTextfield and jList is the important element of java program especially if handling database.

This program will use jTextfield, jList, jLabel, and jButton element to perform the algorithm. In the code view, we create a new method and uses DefaultListModel library. Please follow all the steps to complete this tutorial.

Send Textfield Data to ListView in Java Steps

  1. Add a new jFrame Form and name it what you want.

2. Design your jFrame form by adding the jTextfield, jList, jLabel, and jButton element from your tool pallets. The form should look like the image below.

3. Create a new method inside your class but outside the method.

  1. DefaultListModel<String> model = new DefaultListModel<>();
  2. private void someMethod(){
  3. jList1.setModel(model);
  4. }

jList is the variable name of your list element.

4. Double click your jButton and add the following codes below.

  1. someMethod();
  2. model.addElement(jTextField1.getText());

jTextField1 is the variable name of your text field element

someMethod() is the method name you created in Step 3.

model is the DefaultListModel use to load the data into List.

5. Run your program and it should look like the image below.

Final output of Send Textfield Data to ListView using Java

 

For more information, feel free to leave your comment below, use the contact page of this website or use my contact information.
Email: info@kmjtech.net | Cell. No.: 09468362375

Facebook Comments
(Visited 47 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here