SlideShare una empresa de Scribd logo
1 de 2
Descargar para leer sin conexión
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
Java Swing JTable Example and Tutorial
Written by Administrator
Saturday, 20 August 2011 14:29 - Last Updated Thursday, 01 September 2011 19:15
Result
{loadposition myad}
2 / 2

Más contenido relacionado

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

Java Intro
Java IntroJava Intro
Java Introbackdoor
 
Java Swing Handson Session (1).ppt
Java Swing Handson Session (1).pptJava Swing Handson Session (1).ppt
Java Swing Handson Session (1).pptssuser076380
 
Programa simulacion de ventas de aeropuerto
Programa simulacion de ventas de aeropuertoPrograma simulacion de ventas de aeropuerto
Programa simulacion de ventas de aeropuertoAnel Sosa
 
Java Generics
Java GenericsJava Generics
Java Genericsjeslie
 
Stack Implementation
Stack ImplementationStack Implementation
Stack ImplementationZidny Nafan
 
Intro to scala
Intro to scalaIntro to scala
Intro to scalaJoe Zulli
 
Othello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdfOthello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdfarccreation001
 

Similar a 94 java-swing-jtable-example-and-tutorial (14)

GUI Programming with Java
GUI Programming with JavaGUI Programming with Java
GUI Programming with Java
 
Java Intro
Java IntroJava Intro
Java Intro
 
Java Swing Handson Session (1).ppt
Java Swing Handson Session (1).pptJava Swing Handson Session (1).ppt
Java Swing Handson Session (1).ppt
 
Swing
SwingSwing
Swing
 
Swing
SwingSwing
Swing
 
Programa simulacion de ventas de aeropuerto
Programa simulacion de ventas de aeropuertoPrograma simulacion de ventas de aeropuerto
Programa simulacion de ventas de aeropuerto
 
JavaFX introduction
JavaFX introductionJavaFX introduction
JavaFX introduction
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Stack Implementation
Stack ImplementationStack Implementation
Stack Implementation
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
 
swings.pptx
swings.pptxswings.pptx
swings.pptx
 
Othello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdfOthello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdf
 
AWT New-3.pptx
AWT New-3.pptxAWT New-3.pptx
AWT New-3.pptx
 

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

  • 1. 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
  • 2. Java Swing JTable Example and Tutorial Written by Administrator Saturday, 20 August 2011 14:29 - Last Updated Thursday, 01 September 2011 19:15 Result {loadposition myad} 2 / 2