java program on JTable with data
enter:
Save as
JTableDemo.java
import java.awt.*;
import javax.swing.*;
/* <applet code = "JTableDemo"
width = 400
height=200> </applet> */
public class JTableDemo extends JApplet {
public void init() {
//Get Content Pane
Container contentPane = getContentPane();
//set layout manger
contentPane.setLayout(new BorderLayout());
//Initialize column headings
final String[] colHeads = { "Name",
"Phone", "Fax" };
//Initialize data
final Object[][] data = {
{ "Gail", "4567", "8675" },
{"Keen", "7566", "5555" },
{"Viviane", "5674", "5887"},
{"Anne", "1237", "3333" },
{ "John", "5656", "3144" },
{ "Ellen", "1134", "5335"},
{ "Gail", "4567", "8675" },
{"Keen", "7566", "5555" },
{"Viviane", "5674", "5887"},
{"Anne", "1237", "3333" },
{ "John", "5656", "3144" },
{ "Ellen", "1134", "5335"}
};
//Create the table
JTable table = new JTable(data, colHeads);
//Add table to a scroll pane
int v = ScrollPaneConstants
.VERTICAL_SCROLLBAR_AS_NEEDED ;
int h = ScrollPaneConstants.
HORIZONTAL_SCROLLBAR_AS_NEEDED ;
JScrollPane jsp = new JScrollPane(table, v, h);
// Add scroll pane to the content pane
contentPane.add(jsp, BorderLayout.CENTER);
}
}
No comments:
Post a Comment