0

On my form I have a jtable and a textarea. My table only has 2 columns - ID and Comment Is it possible that when a user clicks on a cell in the comment column. The cell value will appear in the textarea in edit mode?

I did set the cell editor to singleclick

selectTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
TableColumn col = selectTable.getColumnModel().getColumn(1);
DefaultCellEditor singleclick = new DefaultCellEditor(new JTextField()); 
singleclick.setClickCountToStart(1); 
col.setCellEditor(singleclick);

I have a method outputSelection() that gets called from a edit button. The method gets the value from the selected cell and puts the value in the textarea for edit.

Can the click activate the method so the user does not have to click a edit button?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
jkteater
  • 1,381
  • 3
  • 36
  • 69
  • [`TablePopupEditor`](http://stackoverflow.com/a/3591230/230513) is an example. – trashgod Jul 18 '12 at 02:01
  • 1
    don't quite understand your setup: if you do not want to edit the cell value in a textArea outside of the table, simply disable in-cell editing (in the model). Alternatively, if you want in-cell editing, implement a custom editor with a textArea as editing component, f.i. the one referenced by @trashgod – kleopatra Jul 18 '12 at 15:53

2 Answers2

0

You could attach a mouse listener to the table and monitor the mouse clics from there, getting the selected column/row & thus the value

You could supply your own cell editor that updates the text area when the editors value is set

You could extend te jtable & when cell editing is started, update the text area

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
0

Yes, this is a process I learned to use after having duplicate code throughout my swing application. I started making standalone methods that did the work I wanted, and then I call those methods from the action events from the button or mouse click. That way they all execute the same code.

Even if you have a tab or enter key command, you can also have it execute your same method as the others for more consistent code.

If your button performs specific code with cell values, just extract all of that code out into a method that takes the cell value as input. Then you can call that same method from any event and pass in the input data you want to display in the text area.

Logan
  • 2,369
  • 19
  • 20