如何避免两个进程并行运行

发布于 2024-10-15 01:32:03 字数 806 浏览 2 评论 0原文

if (isToCloseTab && selectedTab > -1) {                    
                if (FSView.tabs[selectedTab-1].isChanged()) {
                    String tabName = tabbedPane.getTabTitleAt(selectedTab);
                    JFrame mainFrame = FSApp.getApplication().getMainFrame();
                    savefiledialog = new SaveFileDialog(mainFrame, selectedTab, tabName);
                    savefiledialog.setLocationRelativeTo(mainFrame);
                    FSApp.getApplication().show(savefiledialog);
                }
                if (closeTab) {
                    tabbedPane.removeTabAt(selectedTab);
                }

上面的代码在关闭选项卡时打开一个对话框。根据对话框的用户响应,我决定是否关闭该选项卡。但我面临的问题是该选项卡在对话框响应之前自行关闭。当对话框出现时,选项卡将关闭,而不等待对话框的响应。我希望只有当对话框关闭时,才应根据条件关闭选项卡。你能帮我一下吗?
-提前致谢

if (isToCloseTab && selectedTab > -1) {                    
                if (FSView.tabs[selectedTab-1].isChanged()) {
                    String tabName = tabbedPane.getTabTitleAt(selectedTab);
                    JFrame mainFrame = FSApp.getApplication().getMainFrame();
                    savefiledialog = new SaveFileDialog(mainFrame, selectedTab, tabName);
                    savefiledialog.setLocationRelativeTo(mainFrame);
                    FSApp.getApplication().show(savefiledialog);
                }
                if (closeTab) {
                    tabbedPane.removeTabAt(selectedTab);
                }

The above code opens a dialog box when a tab is closed. Based upon the user response of the Dialog box i decide whether the tab is to be closed or not. But the problem i am facing is that the tab closes itself before the response from the dialog box. When the dialog box appears the tab closes without waiting for the response of the dialog box. I want that when the dialog box is closed only then the tab should be closed based upon the condition. Could you please help me.
-Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

耀眼的星火 2024-10-22 01:32:03

首先要注意的是,“流程”与此无关。进程是一个正在运行的程序,在您的情况下,您可能只有一个进程。

就您而言,您需要的可能是模式对话框。请参阅采用 Dialog.ModalityType 参数的构造函数。然后使用对话框的 setVisible() 方法而不是 show()。对于模式对话框,它将阻塞,直到用户关闭对话框。

当然,这也取决于您的代码的上下文。如果在选项卡关闭后执行它,则没有任何帮助。您需要将其移到其他地方,但在没有看到整体情况的情况下很难说出哪里。

First thing to note, "processes" have nothing to do with this. A process is a program that is running, in your case you probably have just one process.

In your case, what you need is probably a modal dialog. See constructors that take a Dialog.ModalityType argument. Then use the dialog's setVisible() method instead of show(). For modal dialogs, it will block until the user closes the dialog.

Of course, it is also depends on the context of your code. If it is executed after the tab is closed, nothing will help you. You'll need to move it somewhere else, but it is hard to say where without seeing the whole picture.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文