Java Basic Problems

Java JButton below the JTable: How to use and place JButton just under or beneath the JTable.

JBUtton below the JTableHere I am sharing with you another simple but important  fact related to  java JTable and JButton. If you are using JButton and JTable in your software, it may need to place your JButton just under or below the JTable. Here I have shown the way how to place JButton just beneath the JTable. Just copy the code below and run in your pc.

Here is the Code:   JButton Just Below or beneath the JTable

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.table.*;

class ButtonBelowTable 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];

JTextField textBox=new JTextField();

JTextField textBox1=new JTextField();

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

public ButtonBelowTable()

{

setTitle(“Button Below the Table”);

setSize(320,300);

setDefaultCloseOperation (EXIT_ON_CLOSE);

button.setBounds(75,200,90,30);

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

dataValues=new String[][]

                   {

                   {“a”,”2″,”3″},

                   {“b”,”5″,”6″},

                   {“c”,”8″,”9″}

                   };

topPanel=new JPanel();

topPanel.setLayout(null);

getContentPane().add(topPanel);

table=new JTable();

TableModel  model=new myTableModel();

table.setModel(model);

scrollPane=new JScrollPane(table);

scrollPane.setSize(300,200);

scrollPane1=new JScrollPane(button);

scrollPane1.setSize(90,30);

scrollPane1.setBounds(75,200,150,30);

topPanel.add(scrollPane);       

topPanel.add(scrollPane1);

}

public class myTableModel extends DefaultTableModel

{

myTableModel()

{

super(dataValues,columnNames);

}

public boolean isCellEditable(int row,int cols)

{

return true;

}

}

public static void main(String args[])

  {

  ButtonBelowTable x=new ButtonBelowTable();

  x.setVisible(true);

  }  

}

2 thoughts on “Java JButton below the JTable: How to use and place JButton just under or beneath the JTable.”

Leave a Reply

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s