سؤال

I am adding a combobox to the 3rd column of a table so..every time a new row is added it will create a new combobox and adds items from those in vector1

TableColumn ProfileCol = Table.getColumnModel().getColumn(3);
ProfileCol.setCellEditor(new tableList(vector1));

Here tableList is a a below mentioned class that extends DefaultcellEditor and its constructor method is

public tableList(java.util.Vector v) {
    super(new JComboBox(v));

My problem is If I write an action even like

Table.addMouseListener(new java.awt.event.MouseAdapter() {
    @Override    
    public void mouseClicked(java.awt.event.MouseEvent evt) {
        int row = Table.rowAtPoint(evt.getPoint());
        int col = Table.columnAtPoint(evt.getPoint());
        if (row >= 0 && col ==3) {

        }
    }
});

it is not getting triggered..

  1. I need a code that will fire for every selection of item in the combo box
  2. I need a code that will allow me to dynamically update the contents of the combobox that is inserted in the table

Please help with this.

هل كانت مفيدة؟

المحلول

every time I add a new row to the table a new combobox is generated..so how can I write an action listern to them

You should NOT be using an ActionListener.

You have three options:

  1. Override the setValue(...) method of the TableModel to do your processing
  2. Add a TableModelListener to the TableModel. Then you do you processing when the TableModelEvent is generated.
  3. Use a Table Cell Listener on your table to handle the processing.
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top