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

Post on 25-Jun-2015

814 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

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

top related