0

I tried this different ways and none worked. First the explanation:

Picture of the table(gridview):

enter image description here

  1. I have a Table aka (GridView to be specific) which i fill with TextFields.
  2. The right upper triangle can be edited, the bottom one can't.
  3. If the user inputs 1-9 the mirrored field get's the value of 1/(1-9)
  4. The user also has the ability to write 1/(1-9) and the mirrored field get's the value 1-9 (Doesn't matter if the input is 1/9 or the actual number, 0.1111)

The third point is easy, I just used changeListener got both textfields and changed the values. (simple regex: ^[1-9]). This is already done.

I've tried with making if statements with regex checking if it starts with 1 and then 1/ and then 1/(2-9), but it got alot of errors (error that looks something like that =>, I dont' remember the description), it's overly complicated and causes problems later. I also tried that the user can input decimals 0.1111=9 also the same problems.

Is there a listener that I can use that starts when user finished (input is whole). Or how would you tackle the problem?

fabian
  • 80,457
  • 12
  • 86
  • 114
Nino Klajnsek
  • 29
  • 1
  • 5
  • The question should not be : **how to know if the user has finished editing** ? After that it will be easy for you to deal with what he writes. – Bo Halim Dec 12 '16 at 15:53
  • Exactly, is there a option for me to know when he finishes. Or any other ideas on how to solve this problem. – Nino Klajnsek Dec 12 '16 at 15:58
  • You can use a delay, or an interval between each typed character, if the delay is elapsed you call your method ! – Bo Halim Dec 12 '16 at 16:02
  • You can also use a `key` or an `indication` to tell the program to stop editing and start the method (keyboard key / suffix / prefix), otherwise I don't think the program is very clever to guess it all alone ! – Bo Halim Dec 12 '16 at 16:16

2 Answers2

1

Two common ( but not exclusive ) solutions are to:

1) Have the user press enter/return when done editing the field. You can then run your verification function based on that keypress. ( see here )

2) Have the verification run when the field loses focus. ( see here )

Rabbit
  • 131
  • 2
  • I'll try the 2) first, but there is not focus listener for textfield ( in javafx). But can be done this way, i think: http://stackoverflow.com/questions/16549296/how-perform-task-on-javafx-textfield-at-onfocus-and-outfocus – Nino Klajnsek Dec 12 '16 at 16:25
1

This should work:

field.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
        // what happens after Enter is pressed
    }
});
tomasxboda
  • 539
  • 3
  • 15