gpt4 book ai didi

Java如何将非模式对话框中的双击事件结果传递给父框架?

转载 作者:行者123 更新时间:2023-11-30 07:03:13 41 4
gpt4 key购买 nike

我的设计是JFrame 生成一个非模态的 Jdialog。 Jdialog中有一个Jtable。一些搜索结果将显示在 Jtable 中。

我的问题是我向 Jtable 添加了双击鼠标操作,这将从 Jtable 列中获取 ID 值。如何将 ID 值传递给 JFrame? JFrame中有一个Jcombobox,我想为其设置ID值,并将在JFrame中显示有关ID的更多信息。

希望我已经表达清楚了。感谢您提前提供帮助。

最佳答案

您可以将 JComboBox 传递到 JDialog 的构造函数中,然后,在获得 ID 后,您就可以调用 JComboBox 上的方法 添加 ID。示例:

    JComboBox comboBox;

public YourDialogName(JComboBox comboBox /*All the rest of the parameters*/){
this.comboBox = comboBox;
//Do other stuff...
}

private void addIDToComboBox(String id){
comboBox.addItem(id); //Change to however to want to add your ID
}

不过肯定有更好的解决方案。

关于Java如何将非模式对话框中的双击事件结果传递给父框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40541263/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com