Gui problem with java substance Look And Feel
Asked Answered
O

1

0

There is a pretty strange error with setting look and feel. For setting look-and-feel I use the following:


... String scheme = "net.sourceforge.atunes.gui.substance.SubstanceATunesSunLookAndFeel";
try {
            UIManager.setLookAndFeel(scheme);
            UIManager.put(LafWidget.ANIMATION_KIND, LafConstants.AnimationKind.NONE);
            UIManager.put(SubstanceLookAndFeel.TABBED_PANE_CONTENT_BORDER_KIND, SubstanceConstants.TabContentPaneBorderKind.SINGLE_FULL);

            JFrame.setDefaultLookAndFeelDecorated(true);
            JDialog.setDefaultLookAndFeelDecorated(true);
        } catch (ClassNotFoundException e) {
            ExceptionHandler.handleSilently(e);
        } catch (InstantiationException e) {
            ExceptionHandler.handleSilently(e);
        } catch (IllegalAccessException e) {
            ExceptionHandler.handleSilently(e);
        } catch (UnsupportedLookAndFeelException e) {
            ExceptionHandler.handleSilently(e);
        }

which is placed in main function in:


SwingUtilities.invokeAndWait(new Runnable(){
                public void run(){
                    ...
                }

There is no gui elements right before setting look-and-feel, therefore there is no need to execute SwingUtilities.updateComponentTreeUI(...). So, everything is ok, but some users reported very strange bag which is comprises unhandled windows like: When starting program User sees the following screen (the buttons appear only when he moves with the mouse over this area; before doing that the window does not show these buttons.


So, could anybody help me to find the right solution (I don't ask a solution, I just ask the right way to fix it). Firstly, I thought that it happens because of Out of memory error, but the configuration of user's computer is:

Machine configuration:
HP d530 CMT(DF373A)
Windows 7 Ultimate, 32Bit,SP1
2GB Ram
NVIDIA GeForce FX 5700 (1680x1050, 32Bit Col depth)
Java 1.6.0_26

So, I guess Out Of Memory is not the case. Any suggestions, pls.


UPD: so, every GUI creating statements were moved to one SwingUtilities.invokeLater() statement in main function! But, the problem is still reproduced by some users. Also, it's now known, that only view is so weird, but every buttons on it behave as expected! (I mean after pressing Ok button, next MVC is showed and looks well). This bug happens only with very first window which is created right after setting look-and-feel. So, I guess it's not the case of incorrect EDT usig, because of well buttons Listener's execution. Besides, our log (log4j) looks great as nothing weird happens!
Could anyone suggest possible cause?

SOLUTION see http://java.sun.com/products/java-media/2D/perf_graphics.html As commandline parameter where was added:


-Dsun.java2d.noddraw=true
Oddson answered 5/7, 2011 at 7:13 Comment(6)
Could it be that you are updating the UI from a non-EDT thread?Exhibitive
@Exhibitive non-EDT would be my first guess as well - were it not Substance: usually it throws on not being on the EDT. Plus: s/he states that the first snippet is placed inside the invokeAndWait to let it run on the EDTSunup
kleopatra: Ah, didn't know that. I just remember that non-EDT UI updates can really cause a wide variety of visual malfunctions but nice to know that at least one L&F throws (though it shouldn't be responsibility of the L&F to do that).Exhibitive
@Exhibitive could you read the UPD out? I guess, it's something else((Oddson
No idea what an UPD is, but no. I posted my guess, it was wrong. If I had other ideas I would have said so.Exhibitive
@Exhibitive I meant an Update at the end of my post :)Oddson
S
1

agreed with @Joey

if you have original code source from Java.net by Kirill then there are plenty examples that show you

1 ) install UI before

UIManager.installLookAndFeel("Substance " + sInfo.getDisplayName(), sInfo.getClassName());

SwingUtilities.invokeLater(new Runnable() {

   @Override
      public void run() {
           someMainclass.setVisible(true);
      }
}); 

2) your issue with required SwingUtilities.updateComponentTreeUI(someWindow) packed in the try - catch

for (Window w : Window.getWindows()) {
  SwingUtilities.updateComponentTreeUI(w);
}

3) or safiest way, sure with extract top-level containers for point 2dn

SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            try {
                UIManager.setLookAndFeel(new SubstanceOfficeSilver2007LookAndFeel());
                SwingUtilities.updateComponentTreeUI(frame);
            } catch (UnsupportedLookAndFeelException e) {
                throw new RuntimeException(e);
            }
        }
    });
    SwingUtilities.invokeLater(new Runnable() { 

4) you can switch theme(s), L&f, mixing Themes but must be wrapped inside InvokeLater()

5)

EDIT:

@rauch as I mentioned Substance is very sensitive to the EDT, really forgot replace Model from BackGround task without deepest knowledge about EDT and its single threading rules,

hmmm I tried that with replace model directly to avoid some of arrayIndexException plus some exception(s) from Substance (I forgot that that's some month back),

you never fool that with javax.swing.Timer or SwingWorker, sometimes (I think that HightLighter ??? or something from Trident.jar refuse to works correctly ??? and overRun EDT queue) never ever solved that for details,

just I wraped everything (output from Backgroung task to the GUI) to the AbstractAction

EDIT 2. as I read comment by @kleopatra (by mistake I ignore her advice)

would be my first guess as well - were it not Substance: usually it throws 
on not being on the EDT. Plus: s/he states that the first snippet is placed 
inside the invokeAndWait to let it run on the EDT

follows her suggestion, Sustance has own L&f for SwingX, and for me SwingX == kleopatra, I can't give you workAround for that because I really hate invokeAndWait and I avoiding of usage this method

Sempiternal answered 5/7, 2011 at 8:38 Comment(1)
@Sunup :-) why if L&F tutorial talks about another choises ? then I'll add them :-), this thread shows possible EDT issue not issue with L&f, and Substance is best for testing possible EDT fauls ...Sempiternal

© 2022 - 2024 — McMap. All rights reserved.