4 Replies Latest reply: Oct 12, 2012 5:23 AM by 840135 RSS

    GUI Flickers

    840135
      I am working with JTextPane to display chapters of the Bible in HTML form. There is a list box which displays results of phrase search which could be large at times. When I scroll through the search result in the list box, the list box tends to interfere with its surrounding interface. That means part of the window which is near list box will have some scraps of the content of the list box. This happens sometimes especially during fast scrolling.

      To solve this, I put in code for timer to refresh the List box and the main window. That seems to have avoided list box interference, but the main window now looks to flicker - blinks occasionally. It blinks once a minute or so. What do you think is the cause? How can I solve this?
        • 1. Re: GUI Flickers
          sabre150
          lata wrote:
          I am working with JTextPane to display chapters of the Bible in HTML form. There is a list box which displays results of phrase search which could be large at times. When I scroll through the search result in the list box, the list box tends to interfere with its surrounding interface. That means part of the window which is near list box will have some scraps of the content of the list box. This happens sometimes especially during fast scrolling.

          To solve this, I put in code for timer to refresh the List box and the main window. That seems to have avoided list box interference, but the main window now looks to flicker - blinks occasionally. It blinks once a minute or so. What do you think is the cause? How can I solve this?
          Are you using java.awt.List or javax.swing.JList? If you are using java.awt.List then switch to javax.swing.JList . It is not a good idea to mix heavyweight and lightweight components.
          • 2. Re: GUI Flickers
            840135
            I use javax.swing.JList and DefaultListModel
            public JList lsearch;
            DefaultListModel listModel; 
            I purely used swing. Why does swing fail to refresh itself?

            Edited by: lata on Oct 11, 2012 8:55 AM
            • 3. Re: GUI Flickers
              sabre150
              lata wrote:
              I use javax.swing.JList and DefaultListModel
              public JList lsearch;
              DefaultListModel listModel; 
              I purely used swing. Why does swing fail to refresh itself?
              Are you updating the JList outside of the event thread?
              • 4. Re: GUI Flickers
                840135
                This is the code which updates the list. It is called inside button click event.
                public void searchNow(String book, String str)
                 {
                        try
                        {
                            if(str == null || str.isEmpty())
                                return;
                
                            int start = -1;
                            String abbr;
                            String chapter;
                            Hashtable list = new Hashtable();
                            
                            //remove case sensitivity
                            if(gui.option.matchcase == false)
                            {
                                content = content.toLowerCase();
                                str = str.toLowerCase();
                            }
                
                            while(true)
                            {
                                start = content.indexOf(str, start + 1);
                
                                //reached end or not found
                                if(start == -1)
                                    break;
                
                                abbr = findAbbreviation(book, true);
                                chapter = findChapter(start);
                                String temp = abbr + " " + chapter;
                                
                                //if not already in list
                                if((!list.containsKey(temp)) && chapter != null)
                                {
                                    list.put(temp, 1);
                                    listModel.addElement("    " + temp);
                                }
                            }
                        }catch(Exception xp) { info(xp.toString()); }
                 }