java的jpanel一闪一闪的,交换JPanel内容时闪烁

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.

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;

}

An example of code that creates frame with button for swapping panels can be found here: http://pastebin.com/3F2gKBgb

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)

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.

May be the

c.setVisible(false); ; c.setVisible(true);

will help?

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值