我没有找到好的标题,我想对此感到抱歉,
正如你将看到的底部,我已经打电话给
ssframe.add(new JScrollPane(table),BorderLayout.CENTER);
3 次,如果我单击 typeButton 然后 unitButton 它会在屏幕上生成 2 个表格。我希望每个按钮单击一个表,我该怎么做。
private class searchListener implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
JButton clickd = (JButton)e.getSource();
if (clickd==typeButton)
{
try
{
SwingUtilities.updateComponentTreeUI(ssframe);
showTable1("type",typefield.getText());
ssframe.add(new JScrollPane(table),BorderLayout.CENTER);
}catch(Exception a)
{
a.printStackTrace();
JOptionPane.showMessageDialog(null,"Error Code = 0112");
}
}
else if (clickd==unitButton)
{
try
{
SwingUtilities.updateComponentTreeUI(frame);
showTable1("unit",unitfield.getText());
ssframe.add(new JScrollPane(table),BorderLayout.CENTER);
}catch(Exception a)
{
a.printStackTrace();
JOptionPane.showMessageDialog(null,"Error Code = 0112");
}
}
else if (clickd==priceButton)
{
try
{
SwingUtilities.updateComponentTreeUI(frame);
showTable3("price",Integer.parseInt(pricefield.getText()));
ssframe.add(new JScrollPane(table),BorderLayout.CENTER);
}catch(Exception a)
{
a.printStackTrace();
JOptionPane.showMessageDialog(null,"Error C0de = 0112");
}
}
}
编辑:它可能会帮助我解决问题的人:
model.setRowCount(0);
model.fireTableDataChanged();