0

I have a JTable. I want to create an event for one cell that if the user clicks on it, he is able to choose one or more rows from the table and the corresponding IDs are saved in that cell.

enter image description here

So in the example the user would click on "Click here to choose" in row 2 and then click on e.g. row 1 and row 3. The cell "click here to choose" should then be overwritten with something like 1 and 3 afterwards:

enter image description here

I'm thinking of somehow creating a MouseAdapter Event on click on the cell but I have no real idea how to do it. Any idea how I can approach this?

2 Answers 2

1

Use a ListSelectionListener with MULTIPLE_INTERVAL_SELECTION. In the handler, update the table's model using setValueAt() to reflect the change.

Sign up to request clarification or add additional context in comments.

Comments

0

yes you definitely need to use MouseAdapter as below(you have the cell if "if condition become true"):

jt.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mouseClicked(java.awt.event.MouseEvent evt) { int r = jt.rowAtPoint(evt.getPoint()); int c = jt.columnAtPoint(evt.getPoint()); if (r >= 0 && c >= 0) { ...... } } }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.