Monday, 26 March 2018

JTable Demo

Hi All,
See the JTable code


import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
public class JTableDemo extends JFrame
{
    public JTableDemo()
    {
        //headers for the table
        String[] columns = new String[] {
            "Id", "Name", "Hourly Rate", "Part Time"
        };
        
        //actual data for the table in a 2d array
        Object[][] data = new Object[][] {
            {1, "Raju", 40.0, false },
            {2, "Rechu", 70.0, false },
            {3, "Babu", 60.0, true },
        };
        //create table with data
        JTable table = new JTable(data, columns);
        
        //add the table to the frame
        this.add(new JScrollPane(table));
        
        this.setTitle("Table Example");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);      
        this.pack();
        this.setVisible(true);
    }
    
    public static void main(String[] args)
    {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new JTableDemo();
            }
        });
    }  
}

1 comment:

  1. If you're interested in outsourcing product development, I think this piece of content will help you find a product design and development company.

    ReplyDelete

Swing Menu

Hi All, Use this code. ------------------------------------------------------- package placement; import java.awt.*; import java.io.*...