I didn't find good title I guess sorry for this,
As you will see bottom I've called
ssframe.add(new JScrollPane(table),BorderLayout.CENTER);
3 times and if I click the typeButton then unitButton it makes 2 table on the screen. I want to have one table each button clicked, how can I do that.
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");
}
}
}
Edit : It might help someone I have fixed problem with :
model.setRowCount(0);
model.fireTableDataChanged();
There are a number of ways you could do this.
JScrollPane
and replace it's view using setViewportView
, supplying the table you want to show. The JScrollPane
would remain on the frameJScrollPane
and JTable
would be maintained as a single reference and you would then simply change the model.CardLayout
, which would allow you to switch the views as needed