identify each character entred into the cell of jtable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raggwd
    New Member
    • Apr 2009
    • 5

    identify each character entred into the cell of jtable

    Hi,

    I have a JTable and implemented a model. I implemented the setValueAt(...) method to reflect the user input in my model. However, the setValueAt(...) method is not reliable enough, because it only fires when the user actually LEAVES the cell. If he does some input and then hits a button, the model is still in the old state. How can I force each and every input the user makes to be reflected in my model? Do I have to add a listener that updates the model at user input? In that case, can you show me an example, cause Im a Swing noob :)

    Thanks in advance!
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by raggwd
    Hi,

    I have a JTable and implemented a model. I implemented the setValueAt(...) method to reflect the user input in my model. However, the setValueAt(...) method is not reliable enough, because it only fires when the user actually LEAVES the cell. If he does some input and then hits a button, the model is still in the old state. How can I force each and every input the user makes to be reflected in my model? Do I have to add a listener that updates the model at user input? In that case, can you show me an example, cause Im a Swing noob :)

    Thanks in advance!
    You are probably using a JTextField for your editor. Add an InputMethodList ener and a FocusListener and take appropriate actions when such an event is fired.

    kind regards,

    Jos

    Comment

    • raggwd
      New Member
      • Apr 2009
      • 5

      #3
      Thank you for the reply.I am using a default editor...i.e label not textbox.
      I will try with what you hav said and let you know the outcome.
      My requirement is something similar to what happens in excel.
      when we type in a cell of an excel sheet the type char will be displayed both in the cell and in the textbox present on top.Here the text box on top is update every time a character is enter .But in the jtable the update happens only when we press enter.

      Comment

      • raggwd
        New Member
        • Apr 2009
        • 5

        #4
        hi,
        Got a solution for it
        created custom cell editor with jtextbox component as the cell and added key listener to the component....So now its working.
        Thank tou for the reply josah... :)

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by raggwd
          hi,
          Got a solution for it
          created custom cell editor with jtextbox component as the cell and added key listener to the component....So now its working.
          Thank tou for the reply josah... :)
          You're welcome of course but I doubt if your approach works: try to copy and paste a piece of illegal text in your JTextField; there'll be no KeyEvents but there is new text ...

          kind regards,

          Jos

          Comment

          • raggwd
            New Member
            • Apr 2009
            • 5

            #6
            You are right...It didnt work when i pasted the data.
            what shall i do..And where should i add InputMethodList ener and a FocusListener.F or the table or the cell of the table.

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by raggwd
              You are right...It didnt work when i pasted the data.
              what shall i do..And where should i add InputMethodList ener and a FocusListener.F or the table or the cell of the table.
              Your TableCellEditor knows about that JField; add your listeners to that JField.

              kind regards,

              Jos

              Comment

              Working...