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
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
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?