Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JTabel, detecting data changes

843805Dec 28 2006 — edited Jan 10 2007
Hi,

I am new to the JTable component... I have set up a JTabel which displays some sample information. I have to display results I get from one of my methods... There is the Swing/JTable tutorial at http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#modelchange ("Detecting Data Changes"), however, the necessary code has been removed from the tutorial! I hope you can help me...

I have set up the following table:
public class InfoDialog extends JDialog {
	String[] columnNames = {"Type", "Value"};
	Object[][] data = {
			{"Angle", "90"},
			{"Speed", "50"},
	};

	public InfoDialog() {
		Container cp = this.getContentPane();
		setLayout(new BoxLayout(cp, BoxLayout.PAGE_AXIS));
		
		JTable table = new JTable(data, columnNames);
		table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		JPanel tablePanel = new JPanel();
		tablePanel.setLayout(new BorderLayout());
		tablePanel.add(table.getTableHeader(), BorderLayout.PAGE_START);
		tablePanel.add(table, BorderLayout.CENTER);

(...)
From one of my other classes, GameStart, one of the methods, calculateAngle, returns the measured angle. I would like to display this result in the appropriate cell.

In the Swing tutorial I just can read "You can see the code for that method in [PENDING: The Bingo example has been removed.]"

So I am a little bit confused. I think I have to first extend AbstractTableModel, then I have something to do with fireTableCellUpdated... Can you maybe show me a working example or is this "Bingo example" from the Swing available elsewhere?

Thanks for your help!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 6 2007
Added on Dec 28 2006
20 comments
373 views