Java实质外观的Gui问题 [英] Gui problem with java substance Look And Feel

查看:88
本文介绍了Java实质外观的Gui问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置外观时有一个非常奇怪的错误.为了设置外观,我使用以下内容:

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);
        }

放置在主功能中的


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

在设置外观之前没有gui元素,因此无需执行SwingUtilities.updateComponentTreeUI(...).因此,一切都很好,但是一些用户报告说非常奇怪的包是由未处理的窗口组成的,例如: 启动程序时,用户会看到以下屏幕(仅当他将鼠标移到该区域上时,这些按钮才会出现;在执行此操作之前,该窗口不会显示这些按钮.

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:因此,每个创建GUI的语句都被移至main函数中的一个SwingUtilities.invokeLater()语句中!但是,该问题仍然被某些用户重现.而且,现在知道,只有视图太奇怪了,但是它上的每个按钮的行为都与预期的一样! (我的意思是,按确定"按钮后,将显示下一个MVC并看起来不错).仅在设置外观后立即创建的第一个窗口才会发生此错误.因此,我猜不是由于EDT usig错误导致的,不是因为侦听器的按钮执行良好.此外,我们的日志(log4j)看起来很棒,因为没有任何奇怪的事情发生!
有人可以建议可能的原因吗?

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?

解决方案 参见 http://java.sun.com/products/java-media /2D/perf_graphics.html 作为添加了命令行参数的地方:

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


-Dsun.java2d.noddraw=true

推荐答案

同意@Joey

如果您有Kirill的Java.net原始代码源,那么有很多示例向您展示

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

1)先安装UI

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

SwingUtilities.invokeLater(new Runnable() {

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

2)尝试中包含必需的SwingUtilities.updateComponentTreeUI(someWindow)的问题-catch

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

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

3)或最安全的方法,请确保提取2dn点的顶级容器

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)您可以切换主题,L& f,混合主题,但必须包裹在InvokeLater()

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

5)

@rauch就像我提到的那样,Substance对EDT非常敏感,在没有最深入的EDT及其单线程规则知识的情况下,确实忘记了从BackGround任务中替换Model,

@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我尝试直接使用replace模型来避免一些arrayIndexException以及Substance产生的一些异常(我忘了那是几个月前的事了),

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),

您永远不会用javax.swing.Timer或SwingWorker弄糊涂,有时(我认为HightLighter ???或Trident.jar中的某些东西无法正常工作???并溢出EDT队列)从来没有解决过这一点,

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,

我将所有内容(从Backgroung任务输出到GUI)包装到AbstractAction

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

编辑2.当我阅读@kleopatra的评论时(错误地我忽略了她的建议)

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

按照她的建议,SustanceSwingX有自己的L&f,而对我SwingX == kleopatra来说,我无法为您提供workAround,因为我真的很讨厌invokeAndWait,并且避免使用此方法

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

这篇关于Java实质外观的Gui问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆