0

With refrence To The Question! By abg and answer By mKorBel.

And Using J2s Auto Complete Combo Box!

The Code in the Answer By mKorBel For My Case has another problem in the following code when i edit the third row it works fine, but when i click 1st row for edit it sets the value of first row to the selected 3 rd row.

    comboBox.addActionListener(new ActionListener() 
    {

       public void actionPerformed(ActionEvent e) 
       {

          JComboBox comboBox = (JComboBox) e.getSource();
          String    itemStr= comboBox.getSelectedItem().toString();
          int  selectedRowLocal= tblDetailInfoParts.getSelectedRow();

          if (selectedRowLocal != -1) 
          {
             if ((itemStr != null) && (itemStr.compareTo("") != 0) ) 
             {
                tblDetailInfoParts.setValueAt(itemStr, selectedRowLocal, 15);
             }

          }

       }
    });
Community
  • 1
  • 1
  • 1
    still no luck in formatting your code properly? Please try harder ... and remember: this forum formatting software doesn't like tabs :-) – kleopatra Nov 08 '12 at 09:26
  • As to your question: why insist in using unmaintained outdated - to the extent of being jurassic - code examples? AutoComplete is not trivial to get right ... so use a modern, well-maintained implementation like f.i. SwingX – kleopatra Nov 08 '12 at 09:32
  • i mentioned int the last question that i tried SwingX but my main Requirement was not fullfilled that when i type the characters the long list is not filtered and this problem was accpted by mKorbel and he suggested this solution to my problem. – Syed Muhammad Mubashir Nov 08 '12 at 09:37
  • what do you mean by "filtered"? Anyway, note that if you want to use swingX autocomplete as editing component, you need to use a ComboBoxCellEditor instead of the core. – kleopatra Nov 08 '12 at 09:40
  • 2
    @kleopatra basically, as you type, the match is selected in the drop down rather then the list being filter to only show matching results - it's one of the reasons we choice not to use it – MadProgrammer Nov 08 '12 at 09:43
  • @MadProgrammer ahhh ... true, real filtering is not supported (you might consider filing a featrue request :-) - but neither is it in the old java2s example, as far as I remember. – kleopatra Nov 08 '12 at 09:49
  • @ kleopatra no it is working in javas example – Syed Muhammad Mubashir Nov 08 '12 at 10:15
  • I have tested it but has the one bug which ijust mentioned in this question – Syed Muhammad Mubashir Nov 08 '12 at 10:18
  • @MadProgrammer please give my question upvote as u understand my problem – Syed Muhammad Mubashir Nov 09 '12 at 07:38

1 Answers1

1

Instead Of Adding the action Listener to comboBox(i.e. added to the JTable), I added Rob Camick's Table Cell Listener! and in the cell which i added comboBox i listened to change that works perfectly for me. (That was pointed in the comment of my previous question on Java2s Autocomplete Combo Box By @mKorbel)

 private void formWindowOpened(java.awt.event.WindowEvent evt) 
 {
    AddingPartsChangeEvent();
 }     

The Code For My Table Cell Listener To My JTable is as follows

   private void addingPartsChangeEvent() 
   {

      Action actionProd = new AbstractAction() 
      {

         public void actionPerformed(ActionEvent e) 
         {
            try 
            {
               boolean newChk = false;
               TableCellListener tcl = (TableCellListener) e.getSource();
               int selectedRow = tcl.getRow();
               int selectedCol = tcl.getColumn();

               if (selectedCol == 4) 
               {
                  Object partO = tcl.getNewValue();
                  String design = null;
                  String partStr = partO.toString();
                  tblDetailInfoParts.setValueAt(partStr,selectedRow, 15) ;
               }

            } 
            catch (Exception ex) 
            {
               ex.printStackTrace();
            }
         }
      };
      TableCellListener tclProd = new TableCellListener(tblDetailInfoParts,
      actionProd);
    }