Gauvain Klug
Gauvain Klug

Reputation: 591

AutoCompleteTextField disabled after using a Picker

I have a little GUI problem with my app: In one of the forms that I created several weeks ago, there is three AutoCompleteTextfield. If the first doesn't have text inside, the others are disabled.

It work like a charm, BUT there are also three StringPickers, for selecting things like the user, the type... And when the first ACTF is already filled, and thus the two other are enabled, if I pick a String from any of the Pickers, the two ACTF become disabled ! I really don't know why they are disabled, so if anyone has an idea, I'll be grateful :)

Here is the overrided code of the first ACTF:

final DefaultListModel<String> optPart = new DefaultListModel<>();
    actfPart = new AutoCompleteTextField(optPart){

        @Override
        protected boolean filter(String text) {

            if(text.length() == 0) {
                optPart.removeAll();
                actfContact.setEnabled(false);
                actfContact.setHint(language.get("ui.mobile.newtask.hint.contact.nopartner"));
                actfProj.setEnabled(false);
                actfProj.setHint(language.get("ui.mobile.newtask.hint.project.nopartner"));
                return true;
            }
            String[] l = searchPartner(text);
            if(l == null || l.length == 0) {
                actfContact.setEnabled(false);
                actfContact.setHint(language.get("ui.mobile.newtask.hint.contact.nopartner"));
                actfProj.setEnabled(false);
                actfProj.setHint(language.get("ui.mobile.newtask.hint.project.nopartner"));
                return false;
            }

            actfContact.setEnabled(true);
            actfContact.setHint(language.get("ui.mobile.newtask.hint.contact"));
            actfProj.setEnabled(true);
            actfProj.setHint(language.get("ui.mobile.newtask.hint.project"));

            optPart.removeAll();
            for(String s : l) {
                optPart.addItem(s);
            }
            return true;
        }

        private String[] searchPartner(String text) 
        {
            Partner[] parts = RESTeCust1.searchSomePartners(0, 30, text);
            String[] strs = new String[parts.length];
            int i = 0;
            for (Partner part : parts) {
                strs[i] = part.getLabel() + " REF: " + part.getReference();
                i++;
            }

            return strs;
        }

    };

The others ACTF and the string Pickers are initialized before calling this code.

Upvotes: 1

Views: 30

Answers (1)

Shai Almog
Shai Almog

Reputation: 52760

Derive one of the other AutoCompleteTextField instances and override setEnabled(boolean) place a breakpoint in the overriden method and reproduce the issue. You will see a callstack indicating exactly who invoked setEnabled(false) and why...

Upvotes: 2

Related Questions