-1

I'm searching a way to draw dots in Cartesian coordinates in real-time when entering a value to a JTable. When I enter 2 to first column and 3 to second columns, without clicking a button, the point should be at (2,3) in coordinates. What are some ways to do this in Java?

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Melih
  • 9
  • 3

1 Answers1

1

It sounds like you want to create a scatter plot that reflects the current entries in a two column JTable. One approach would be to add a TableModelListener to your JTable, as shown here. In your implementation of tableChanged(), update the plot. Using , you would update the XYSeries contained in an XYSeriesCollection used to create a scatter plot, as shown here. The listening chart will update itself in response. In the brute force approach, you could clear() the series and iterate through the table's TableModel, adding current values to the series as you go. Alternatively, identify the row that changed and update() the corresponding entry in the series.

Starting from the first example cited, you could simply replace the JList on the right with the ChartPanel used in the second example. The TableModelListener obviates the need for a button to generate the update.

image image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045