0

My JPanel ButtonMenu is having slow UI update over a period of use (Lets say sometimes in 4th click sometimes 20th). The issue is simple, the painting is just getting delayed. So i have done lot of reading and came across a lot of suggestions,especially this, this and this. But nothing seems to fix it yet. So my questions are

  1. When to use these following parameters to fix an application? And how to check if they have taken effect in a system?

    Dsun.java2d.xrender Dsun.java2d.pmoffscreen Dsun.java2d.d3d

  2. This used to work well before java 8. But I can't say for sure if java 8 is the problem as it is working at sometimes. Rendering is breaking over a period of use, again this is a judgement on observation. When it gets delayed, it just won't update until something else wakes it up.


Update:

So I have found the real issue. My method populating the button and doing the UI update looks like:

public void showButtonMenuList(final MenuList menulist)
{
    GuiExecutor.getInstance().update(new Runnable()
    {
        public void run()
        {
            notifyListenersOfButtonMenuShow();
            buttonMenu = ButtonMenu.makeButtonMenu(menulist.getMenuOptions(), MyBigPanel.this);
            leftSidePanel.removeAll();
            leftSidePanel.add(buttonMenu.getPanel(), BorderLayout.CENTER);
        }
    });
    freshup();
}

The notifyListenersOfButtonMenuShow() is:

public void notifyListenersOfButtonMenuShow(){
        Object[] ButtonMenuListenerslist = ButtonMenuListeners.toArray();
        for (int ButtonMenuListenerslistIterator = 0;ButtonMenuListenerslistIterator < ButtonMenuListenerslist.length;ButtonMenuListenerslistIterator++){
            ((ButtonMenuListener) ButtonMenuListenerslist[ButtonMenuListenerslistIterator]).menuShowing();
        }
}

Here the freshup() is:

protected void freshup()
{
    panel.repaint();
    panel.revalidate();
}

and update() belongs to my GuiExecutor class which looks like:

public void update(final Runnable runnable)
{
    if (SwingUtilities.isEventDispatchThread())
    {
        runnable.run();
    }
    else
    {
        try
        {
             SwingUtilities.invokeLater(runnable);
        }
        catch (Exception ex)
        {}
    }
}

So if anything within the run gets delayed freshup() would have already got executed. What is the best way around this rather than calling freshup() within the run(). May be a way to fix the inconsistent delays or a better design pattern to make this thread safe?

Community
  • 1
  • 1
RBz
  • 896
  • 3
  • 17
  • 34
  • Your code snippet looks incomplete; did you paste it correctly? – Gorbles Dec 07 '15 at 10:08
  • In my code i set those parameters to false. I didn't gave it in the question as my question was about knowing what these parameters do in general and how to check if their status in our system. – RBz Dec 07 '15 at 11:38
  • Ahh, sorry, I thought they were package references at the start of a class! Going on your first link there's an issue with rendering in Swing in Java 8, but I think your issue might be different. Could you post your `JButton` code? For your VM argument questions, a quick Google found this - https://docs.oracle.com/javase/8/docs/technotes/guides/2d/flags.html#pmoffscreen – Gorbles Dec 07 '15 at 15:00
  • What is `notifyListenersOfButtonMenuShow()` doing? There's a lot going on here that isn't explained; you might need to post more of a runnable example for people to help you. I'm unsure why you're doing such specific EDT / thread work, most of that should be handled by default. But that's more just me not being familiar with your needs. – Gorbles Dec 29 '15 at 11:34
  • @Gorbles Added notifyListenersOfButtonMenuShow(). And also what do you mean by specific EDT / thread work. Could it be a potential performance issue? – RBz Dec 30 '15 at 05:51
  • sorry for not getting back to you, been ill. My issue with your explicit `.isEventDispatchThread` block is that it's unnecessary, but I **still** can't see all of your code so I'm not sure how it fits together. Is there something stopping you from pasting all of your code? – Gorbles Jan 04 '16 at 12:26

0 Answers0