Announcement Announcement Module
No announcement yet.
Problem w/ cursor focus when form control is in JScrollPane Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem w/ cursor focus when form control is in JScrollPane


    I have encountered a problem when validation error is detected in a form, where the form control is contained in a JScrollPane in an AbstractView.

    I noticed that when I put the form control in a JScrollPane, the cursor on textfields that are invalid loses focus and the cursor automatically jumps to the next widget (JTextField/JRadioButton/...). When I place the cursor back on the textfield with the error and cause subsequent validation errors on it, it is fine; the cursor doesn't jump. The problem lies with the initial detection of the validation error on the first textfield. Now, if I did not put the form component in a JScrollPane, all is fine; the cursor doesn't jump to the next widget automatically.

    I tried this out on the pet clinic sample, and it is also the case.

    To replicate this, in the class, add the form control into a JScrollPane in the method createFormControl(), like so:

        protected JComponent createFormControl() {
            TableFormBuilder formBuilder = new TableFormBuilder(getFormModel());
            this.firstNameField = formBuilder.add("firstName")[1];
            return new JScrollPane(formBuilder.getForm());
    Now, in the first name field, just backspace till no values are in the field. This will cause a validation error. Notice that the cursor automatically jumps to the next field.

    Does anyone know why this is occuring and a possible fix for it? I can't seem to locate the root cause.

    Thanks in advance.