Gui problem with java substance Look And Feel

允我心安 提交于 2019-12-02 20:19:24

问题


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 

回答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



来源:https://stackoverflow.com/questions/6579087/gui-problem-with-java-substance-look-and-feel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!