gpt4 book ai didi

java - 如何从不同的表单更新 jtable?

转载 作者:行者123 更新时间:2023-12-02 07:08:50 25 4
gpt4 key购买 nike

public class A extends JInternalFrame implements ActionListener
{
private JTable table;
private JButton button;

public A()
{
button = new JButton("Load Dialog");
button.addActionListener(this);

initializeTable();
}

public void initializeTable()
{

table = new JTable();
MyTableModel mymodel = new MyTableModel();

table.setModel(mymodel);
}

public void changeModel(NewTableModel model)
{
table.setModel(model);
}

public void actionPerformed(ActionEvent e)
{
MyDialog dialog = new MyDialog(null,true);
dialog.setVisible(true);
}
}

public class MyDialog extends JDialog implements ActionListener
{

private JButton button;

public MyDialog(JFrame parent,bool modal)
{
button = new JButton("Change Model");
button.addActionListener(this);

super(parent,modal);
}

public void actionPerformed(ActionEvent e)
{
NewTableModel newModel = new NewTableModel();
A a = new A();

a.changeModel(newModel);
}
}

我想更新第二个表单(MyDialog)中第一个表单(A)的表。我想为其设置一个新模型,当我单击 MyDialog 中的更改模型按钮时,它将自动更新第一种形式(A)中的模型,并且其所有显示的值将被来自 MyDialog 的新模型替换。怎么可能做到这一点?希望有人可以指导我。谢谢。

最佳答案

如果您想用 MyDialog 中的模型完全替换 A 中的模型,为什么不在 MyDialog 中提供一个返回的 getter新模型并在对话框关闭后简单地替换为 A(假设它是模式对话框),否则您需要将 A 的引用传递给 MyDialog

关于java - 如何从不同的表单更新 jtable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15778306/

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