Swing 更新谜题
我有一个 Jtree,其中的节点代表用户可以调用和查看的图像。有时加载图像需要四到五秒的时间。理想情况下,我希望在用户等待时显示等待光标,并选择树中选择的节点。然而,我发现用户单击该节点,似乎没有发生任何事情,然后出现图像,然后选择该节点(等待光标永远不会出现或更可能出现非常短暂,然后立即消失。我'我尝试重新绘制树和小程序,以尝试强制行为按我想要的顺序发生,到目前为止,我没有任何建议? 以下是一些给我带来问题的 Swing 代码的一部分:
thisApplet.setCursor(new Cursor(Cursor.WAIT_CURSOR));
selectdocumentTreeLeaf(); // a JTree with nodes representing images
tree.repaint();
thisApplet.repaint();
tree.setEnabled(false); //disabled so users don't keep clicking on it.
result = createImage(queue.q[pointer].currentPage); //where the image is fetched
thisApplet.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
I have a Jtree with nodes representing images that the user can call up and view. Sometimes it takes the images up to four or five seconds to load. Ideally, I would like wait cursor to show while the user is waiting and the node selected in the tree to be selected. However, what I'm find is that the user clicks on the node, nothing appears to happen and then the image appears and then the node is selected (the wait cursor never appears or more likely appears very briefly and then disappears immediately. I've tried repainting both the tree and the applet to try to force the behavior to happen in the sequence I want. So far, I've not had any luck. Any suggestions?
Here is a section of some Swing code that is giving me problems:
thisApplet.setCursor(new Cursor(Cursor.WAIT_CURSOR));
selectdocumentTreeLeaf(); // a JTree with nodes representing images
tree.repaint();
thisApplet.repaint();
tree.setEnabled(false); //disabled so users don't keep clicking on it.
result = createImage(queue.q[pointer].currentPage); //where the image is fetched
thisApplet.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为佩斯是有钱的。使用后台线程(例如 SwingWorker),您的问题将得到解决。请查看Swing 中的并发,了解有关 EDT 和线程问题。例如,
I think Pace is on the money. Use a background thread such as a SwingWorker and your problems will be solved. Please check out Concurrency in Swing for more details on the EDT and thread problems. e.g.,