How do I use a form to insert data into a JTable?

I have a JFrame with JTextFields for Name, Department, Original Price, and Sale Price. I want to take those values and insert them into a Table or JText Area. What would be the method I should use? Here is the table I have, I tried add. or insert or data = but I can't seem to get the data to display.

public String[] titles = new String[] {"Item Name", "Department","Original Price","Sale Price"};

public String[][] data = new String[][] {{"", "","",""},{"","","",""}};

JTable results = new JTable(data, titles);

JScrollPane scrollPane = new JScrollPane(results);

getContentPane().add(scrollPane, BorderLayout.CENTER);

setVisible(true);

This needs to be executed on a button click so that is the main hurtle I am facing. I just need to get pointed in the right direction please,

Thanks

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Helpful Social

Copyright © 2024 QUIZLS.COM - All rights reserved.