问题描述
我正在使用Java3D和Jmol(这是3D中化学结构的查看器)进行的项目.我必须创建一个视图,该视图能够在结构的Java3D和Jmol表示之间切换.
I'm working on a project using Java3D and Jmol (it's a viewer for chemical structures in 3D). I have to create view that is able to switch between Java3D and Jmol representation of structures.
我已经做到了,但是当我将JPanels与JmolPanel和Canvas3D交换时,交换区域会闪烁.
I have managed to do that, but when I swap JPanels with JmolPanel and Canvas3D in them, I get blinking of the swapped area.
我只是通过做以下事情来交换面板:
I'm swapping panels simply by doing:
public static void changeView(JPanel c) {
c.removeAll();
if (var) {
c.add(canvas);
} else {
c.add(jmolPanel);
}
c.revalidate();
var = !var;
}
可以在此处找到创建带有用于交换面板的按钮的框架的代码示例: http://pastebin.com/3F2gKBgb
An example of code that creates frame with button for swapping panels can be found here: http://pastebin.com/3F2gKBgb
要运行此示例,您需要Jmol.jar(可以在此处 http://jmol.sourceforge中找到. net/download/)和Java3D(http://java3d.java.net/binary-builds.html)
To run this example you need Jmol.jar (it can be found here http://jmol.sourceforge.net/download/) and Java3D (http://java3d.java.net/binary-builds.html)
我尝试在JPanels中设置双缓冲,但这无济于事.您是否知道如何解决闪烁问题?
I tried setting double buffering in JPanels, but it doesn't help. Do you have any idea how the blinking problem could be resolved?
推荐答案
如果通过闪烁表示您要在移除然后添加子面板时对其进行重新粉刷,那么我将尝试停止重新粉刷,进行所有交换,然后启用父面板的重新粉刷.
If by blinking you mean it's getting repainted while you are removing and then adding sub-panel then I would try to stop repainting, do all the swapping and then enable repainting of the parent panel.
可能是c.setVisible(false); <your swapping code>; c.setVisible(true);
有帮助吗?
或创建一个子面板sc,您将使其不可见,并向其中添加可交换组件,以便父面板始终保持可见状态.可能是围绕双缓冲问题的破解,应该从一开始就解决了您的问题,但是值得一试.
or create a subpanel sc, that you will make invisible to which you will add your swappable components, so that the parent panel stays visible at all times. It may be a hack around double-buffering problem that should have solved your problem to begin with, but it's worth a try.
这篇关于交换JPanel内容时闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!