Java JButton Click event and JTable: Click on the JButton and the JTable will show or appear

Here I am sharing you a simple but useful way about JButton and JTable. Sometimes in designing   software, where we are using JButton and JTable, we may need to code or design in such a way that just user will click on the JButton (by using JButton ActionListener) and the JTable will show or appear with its value. Copy the code below and run on your computer.

Here is the code:


import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.table.*;

class ClickandTable extends JFrame


private JPanel topPanel;

private JTable table;

public JScrollPane scrollPane;

public JScrollPane scrollPane1;

private String[] columnNames=new String[3];

private String[][] dataValues=new String[3][3];

JButton button=new JButton(“Click Here”);

public ClickandTable()


setTitle(“Button Click and JTable Appears”);


setDefaultCloseOperation (EXIT_ON_CLOSE);


columnNames=new String[] {“Column 1″ ,”Column 2”, “Column 3”};

dataValues=new String[][]






topPanel=new JPanel();



table=new JTable();

scrollPane=new JScrollPane(table);


scrollPane1=new JScrollPane(button);






                                    new ActionListener()


                                    public void actionPerformed(ActionEvent event)


                                    TableModel  model=new myTableModel();






public class myTableModel extends DefaultTableModel






public boolean isCellEditable(int row,int cols)


return true;



public static void main(String args[])


  ClickandTable x=new ClickandTable();



}JButton click and JTable appear

One Response to Java JButton Click event and JTable: Click on the JButton and the JTable will show or appear

  1. Thesubhuman says:

    Thank You very much!!! The problem seems so simple yet it took me a considerable amount of time to find an answer. Thanks again. 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: