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
Copyright © 2024 QUIZLS.COM - All rights reserved.
Answers & Comments
Verified answer
http://docs.oracle.com/javase/6/docs/api/javax/swi...
http://docs.oracle.com/javase/tutorial/uiswing/eve...
You need an action listener for the button, and you need to consult the JTextArea api. Both are linked for you.