Table Display


run

---(Source List)---

//Example1a.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class Example1a{
  //data
  Object[] colNames={"name","material","size","color","note"};
  Object[][] rowData={
    {"A01","cloth","large","white","soft"},
    {"K01","thread","thin","red","strong"},
    {"U01","paper","middle","yellow","cheap"},
    {"S01","string","middle","black","quality"},
  };
  //main
  public static void main(String args[]){
    Example1a sample = new Example1a();
  }
  //constructor
  public Example1a(){
    JFrame f=new JFrame("table display");
    f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
    JTable t= new JTable(rowData, colNames);
    t.setRowHeight(20);
    t.setGridColor(Color.gray);
    JScrollPane sp=new JScrollPane();
    sp.getViewport().setView(t);
    sp.setPreferredSize(new Dimension(300, 120));
    JPanel p=new JPanel();
    p.add(sp);
    f.getContentPane().add(p,BorderLayout.CENTER);
    
    f.setBounds(50,50,320,160);
    f.setVisible(true);
  }
}