Switch to full style
Graphics and animation Java code examples
Post a reply

JTable usage example with JPanel

Thu Feb 07, 2013 10:27 pm

JTable usage example
java code
/*
* Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for NON-COMMERCIAL purposes and without
* fee is hereby granted provided that this copyright notice
* appears in all copies. Please refer to the file "copyright.html"
* for further important copyright and licensing information.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*/
import com.sun.java.swing.JTable;
import com.sun.java.swing.JScrollPane;
import com.sun.java.swing.JPanel;
import com.sun.java.swing.JFrame;
import java.awt.GridLayout;
import java.awt.Dimension;
import java.awt.event.WindowListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class SimpleTableDemo extends JPanel {
final Object[][] data = {
{"Mary", "Campione", "Snowboarding", "5"},
{"Alison", "Huml", "Rowing", "3"},
{"Kathy", "Walrath", "Chasing toddlers", "2"},
{"Mark", "Andrews", "Speed reading", "20"},
{"Angela", "Lih", "Teaching high school", "4"}
};
final Object[] columnNames = {"First Name",
"Last Name",
"Sport",
"Est. Years Experience"};
public SimpleTableDemo() {
JTable table = new JTable(data, columnNames);

//Create the scroll pane and add the table to it.
JScrollPane scrollPane = JTable.createScrollPaneForTable(table);
scrollPane.setPreferredSize(new Dimension(400, 100));

//Add the scroll pane to this panel.
setLayout(new GridLayout(1, 0));
add(scrollPane);
}

public static void main(String[] args) {
JFrame frame = new JFrame("SimpleTableDemo");

frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});

frame.getContentPane().add("Center", new SimpleTableDemo());
//frame.setSize(400, 125);
frame.pack();
frame.setVisible(true);
}
}




Post a reply
  Related Posts  to : JTable usage example with JPanel
 Put image in JPanel     -  
 JTable example     -  
 Jtable with multiple headings     -  
 Usage of UL tag     -  
 Usage of sub tag     -  
 dir tag usage     -  
 dd tag usage     -  
 var tag usage     -  
 usage of ol tag     -  
 Usage of sup tag     -  

Topic Tags

Java Swing