0
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的新模型所取代。這怎麼可能呢?希望有人能指導我。謝謝。如何從其他表單更新jtable?