Hi,

I have a new problem.

I can draw a JTable and a JButton in a window.
The table has 5 columns and 5 rows.

This is what I want to do.
When the button is clicked, the table should have 4 columns and 4 rows.
Who can help me with this??

Thanks for reading my problem.

Code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class GridBagWindow extends JFrame {
    boolean inAnApplet = true;
    final boolean shouldFill = true;
    final boolean shouldWeightX = true;

     JTable table;
     

     
    public GridBagWindow() {
    	
    	
        
        // new Data
        
        JButton NewDataButton = new JButton("This button should change the layout of the Table");
        
        NewDataButton.setMnemonic(KeyEvent.VK_I);
        NewDataButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

            //************************//
            //THIS DOES NOT WORK !!!!
            // WHO CAN FIX THIS ?????
            //************************//
           
            table = new JTable(4, 4);
            table.repaint();
            
            }
            
 
        });
        

        table = new JTable(5, 5);

        table.setRowSelectionAllowed(true);
        table.setPreferredScrollableViewportSize(new Dimension(800, 200));
        
    
        
        
        
        Container contentPane = getContentPane();
        GridBagLayout gridbag = new GridBagLayout();
        GridBagConstraints c = new GridBagConstraints();
        contentPane.setLayout(gridbag);
        if (shouldFill) {
           
            c.fill = GridBagConstraints.HORIZONTAL; 
        }
   

        if (shouldWeightX) {
            c.weightx = 0.5;
        }
        c.gridx = 0;
        c.gridy = 0;
        gridbag.setConstraints(NewDataButton, c);
        contentPane.add(NewDataButton);
        
        
        c.gridx = 0;
        c.gridy = 1;
        gridbag.setConstraints(table, c);
        contentPane.add(table);
        
        
         //Create the scroll pane and add the table to it. 
        JScrollPane scrollPane = new JScrollPane(table);

        //Add the scroll pane to this window.
        gridbag.setConstraints(scrollPane, c);
        getContentPane().add(scrollPane);



        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                if (inAnApplet) {
                    dispose();
                } else {
                    System.exit(0);
                }
            }
        });
    }

    public static void main(String args[]) {
        GridBagWindow window = new GridBagWindow();
        window.inAnApplet = false;

        window.setTitle("Change the Table layout ...");
        window.pack();
        window.setVisible(true);
    }
}