Java 物质外观和感觉的 GUI 问题
设置外观有一个非常奇怪的错误。为了设置外观,我使用以下内容:
... 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(...)。所以,一切都很好,但是一些用户报告了非常奇怪的包,其中包含未处理的窗口,例如: 启动程序时,用户会看到以下屏幕(仅当他将鼠标移到该区域上时才会出现按钮;在此之前,窗口不会显示这些按钮。
那么,任何人都可以帮助我找到正确的解决方案吗(我不知道)询问解决方案,我只是询问正确的解决方法)。首先,我认为这是因为内存不足错误而发生的,但用户计算机的配置是:
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
所以,我猜内存不足不是这种情况。 任何建议,请。
UPD:因此,每个 GUI 创建语句都被移至主函数中的一个 SwingUtilities.invokeLater() 语句!但是,一些用户仍然重现了该问题。另外,现在知道,只有视图是如此奇怪,但它上面的每个按钮都按预期运行! (我的意思是按“确定”按钮后,将显示下一个 MVC,并且看起来不错)。此错误仅发生在设置外观后立即创建的第一个窗口。所以,我想这不是 EDT 使用不正确的情况,因为按钮监听器的执行很好。此外,我们的日志(log4j)看起来很棒,没有发生任何奇怪的事情!
有人能提出可能的原因吗?
解决方案 请参阅 http://java.sun.com/products/java-media /2D/perf_graphics.html 作为命令行参数添加:
-Dsun.java2d.noddraw=true
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
同意@Joey
,如果您有 Kirill 来自 Java.net 的原始代码源,那么有很多示例向您展示
1)在 2)之前安装 UI
所需的
SwingUtilities.updateComponentTreeUI(someWindow)
打包的问题try - catch3) 或最安全的方式,请确保使用提取点 2dn 的顶级容器
4) 您可以切换主题、L&f、混合主题,但必须包含在其中
InvokeLater()
5)
编辑:
@rauch,正如我提到的,物质对 EDT 非常敏感,真的忘记了从 BackGround 任务中替换模型,而没有对 EDT 及其单线程规则有最深入的了解,
嗯,我尝试过直接替换模型以避免一些 arrayIndexException 加上来自 Substance 的一些异常(我忘记那是几个月前的事了),
你永远不会用 javax.swing.Timer 或 SwingWorker 愚弄它,有时(我认为 HightLighter ??? 或 Trident.jar 中的某些内容拒绝正常工作 ??? 并溢出 EDT 队列)从未解决过这个问题的详细信息,
只是我将所有内容(从 Backgroung 任务输出到 GUI)包装到 AbstractAction
编辑2.当我阅读@kleopatra的评论时(我错误地忽略了她的建议)
遵循了她的建议,Sustance有自己的L&f
SwingX
,对于我SwingX == kleopatra
,我无法为您提供解决方法,因为我真的很讨厌invokeAndWait
并且我避免使用这个方法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
2) your issue with required
SwingUtilities.updateComponentTreeUI(someWindow)
packed in the try - catch3) or safiest way, sure with extract top-level containers for point 2dn
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)follows her suggestion,
Sustance
has ownL&f
forSwingX
, and for meSwingX == kleopatra
, I can't give you workAround for that because I really hateinvokeAndWait
and I avoiding of usage this method