Tuesday, January 15, 2013

JTable Example In Java.♥


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

class SimpleTableExample
        extends     JFrame
 {
   
    private    JPanel        topPanel;
    private    JTable        table;
    private    JScrollPane scrollPane;

        public SimpleTableExample()
    {
       
        setTitle( "Simple Table Application" );
        setSize( 300, 200 );
        setBackground( Color.gray );

       
        topPanel = new JPanel();
        topPanel.setLayout( new BorderLayout() );
        getContentPane().add( topPanel );

       
        String columnNames[] = { "Column 1", "Column 2", "Column 3" };

                String dataValues[][] =
        {
            { "12", "234", "67" },
            { "-123", "43", "853" },
            { "93", "89.2", "109" },
            { "279", "9033", "3092" }
        };

       
        table = new JTable( dataValues, columnNames );

       
        scrollPane = new JScrollPane( table );
        topPanel.add( scrollPane, BorderLayout.CENTER );
    }

    public static void main( String args[] )
    {
       
        SimpleTableExample mainFrame    = new SimpleTableExample();
        mainFrame.setVisible( true );
    }
}

OUTPUT :


No comments: