Hi everybody ,
Plz solve my problem . I want to display table on a frame & I am able to display but not with proper size & position . How can I do this ? Plz provide code if possible
Here is the code :
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SimpleTableDemo extends JFrame {
public void show() {
Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Chasing toddlers", new Integer(2), new Boolean(false)},
{"Mark", "Andrews",
"Speed reading", new Integer(20), new Boolean(true)},
{"Angela", "Lih",
"Teaching high school", new Integer(4), new Boolean(false)}
};
String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};
JTable table = new JTable(data, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
JPanel panel = new JPanel();
panel.add(scrollPane);
JFrame frame = new JFrame();
frame.getContentPane().add(panel, BorderLayout.CENTER);
frame.setSize(900,200);
frame.setVisible(true);
}
public static void main(String[] args) {
SimpleTableDemo frame = new SimpleTableDemo();
frame.show();
}
}