94 java-swing-jtable-example-and-tutorial

2
Java Swing JTable Example and Tutorial Written by Administrator Saturday, 20 August 2011 14:29 - Last Updated Thursday, 01 September 2011 19:15  This Java Swing tutorial will demonstrate you how to use JTable companent in java swing and also how you can use multi dimension Object array to populate JTable. As a container of the Table I used Java Frame. - Compile: javac SwingTable.java - Run: java SwingTable  SwingTable.java  //copyrighted by topsourcecode.com import java.awt.Color; import javax.swing.*; public class SwingTable{ public static void main(String[] args) { JFrame frame = new JFrame("Populate Table with Data"); JPanel panel = new JPanel(); //Table Parameters String col[] = {"Name","Country","Telephone"}; Object values[][] = {{"John","USA","087689689"}, {"Sulaiman","Africa","989009980"}, {"Khan","India","098790998"}, {"Alex","Australia","989900098"}, {"Tsong","China","899866444"}}; JTable table = new JTable(values, col); table.setBackground(Color.cyan); //Table Container Paramerters JScrollPane pane = new JScrollPane(table); panel.add(pane); frame.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } }  1 / 2

Upload: prakash-sweet

Post on 25-Jun-2015

814 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 94 java-swing-jtable-example-and-tutorial

Java Swing JTable Example and Tutorial

Written by AdministratorSaturday, 20 August 2011 14:29 - Last Updated Thursday, 01 September 2011 19:15

 

This Java Swing tutorial will demonstrate you how to use JTable companent in java swing andalso how you can use multi dimension Object array to populate JTable. As a container of theTable I used Java Frame.

- Compile: javac SwingTable.java - Run: java SwingTable

 

SwingTable.java

 

//copyrighted by topsourcecode.com import java.awt.Color; import javax.swing.*; publicclass SwingTable{ public static void main(String[] args) { JFrame frame = newJFrame("Populate Table with Data"); JPanel panel = new JPanel(); //TableParameters String col[] = {"Name","Country","Telephone"}; Object values[][] ={{"John","USA","087689689"}, {"Sulaiman","Africa","989009980"}, {"Khan","India","098790998"}, {"Alex","Australia","989900098"}, {"Tsong","China","899866444"}}; JTable table = new JTable(values, col); table.setBackground(Color.cyan); //Table Container Paramerters JScrollPane pane =new JScrollPane(table); panel.add(pane); frame.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } }

 

1 / 2

Page 2: 94 java-swing-jtable-example-and-tutorial

Java Swing JTable Example and Tutorial

Written by AdministratorSaturday, 20 August 2011 14:29 - Last Updated Thursday, 01 September 2011 19:15

Result

{loadposition myad}

2 / 2