table swing java

Discussion in 'Software' started by farmer, Jun 3, 2010.

  1. farmer

    farmer

    Joined:
    Jun 3, 2010
    Messages:
    1
    import javax.swing.*;
    import javax.swing.table.*;

    import java.awt.*;
    import java.util.Vector;


    import org.omg.CORBA.OBJECT_NOT_EXIST;
    import org.omg.CORBA.OBJ_ADAPTER;
    public class gui {

    private JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="44,19"
    private JPanel jContentPane = null;
    private JTable jTable = null;
    private Object[][] table = null;
    private JPanel jPanel = null;
    private DefaultTableModel model = null;
    private String[] NameOfColumn = null;

    public void initialize(){
    getJFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getJFrame().setVisible(true);
    }
    /**
    * This method initializes jFrame
    *
    * @return javax.swing.JFrame
    */
    private JFrame getJFrame() {
    if (jFrame == null) {
    jFrame = new JFrame();
    jFrame.setSize(new Dimension(500, 500));
    jFrame.setContentPane(getJPanel());
    update();
    }
    return jFrame;
    }

    /**
    * This method initializes jContentPane
    *
    * @return javax.swing.JPanel
    */
    private JPanel getJContentPane() {
    if (jContentPane == null) {
    jContentPane = new JPanel();
    jContentPane.setLayout(null);
    jContentPane.add(getJPanel(), null);

    }
    return jContentPane;
    }

    /**
    * This method initializes jTable
    *
    * @return javax.swing.JTable
    */
    private JTable getJTable() {
    if (jTable == null) {
    model = new DefaultTableModel(table,NameOfColumn);
    jTable = new JTable(model);
    jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    JTableHeader header = jTable.getTableHeader();
    header.setBackground(Color.yellow);
    }
    return jTable;
    }

    public void addcolumn(String NameOfColumn){
    model.addColumn(NameOfColumn);
    }

    public void addrow(Vector vec){
    model.addRow(vec);
    }
    public Vector<String> getnewvec(){
    Vector<String> vec = new Vector<String>();
    for(int i = 0;i<5;i++){
    vec.add(String.valueOf((int)(Math.random()*10)));
    }
    return vec;
    }

    public void update(){
    addcolumn("1");
    addcolumn("2");
    addcolumn("3");
    addcolumn("4");
    addcolumn("5");

    for(int i = 0;i<10;i++){
    addrow(new Vector<String>(getnewvec()));
    }
    Vector<String> tmp = new Vector<String>();
    for(int i = 0;i<10;i++){
    tmp.add(String.valueOf(i));
    }
    model.addColumn("new",tmp);
    model.setRowCount(200);
    model.setColumnCount(200);


    }
    /**
    * This method initializes jPanel
    *
    * @return javax.swing.JPanel
    */
    private JPanel getJPanel() {
    if (jPanel == null) {
    jPanel = new JPanel();
    JScrollPane pane = new JScrollPane(getJTable());
    jPanel.add(pane);
    }
    return jPanel;
    }

    }
     
    farmer, Jun 3, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joachim Krais
    Replies:
    2
    Views:
    15,433
    Andre Beck
    Nov 23, 2003
  2. John Ramsden
    Replies:
    0
    Views:
    1,083
    John Ramsden
    Jul 24, 2004
  3. zher
    Replies:
    2
    Views:
    9,237
  4. Darren Green
    Replies:
    1
    Views:
    7,202
    Walter Roberson
    Mar 19, 2005
  5. hugh jass
    Replies:
    3
    Views:
    1,087
    Helen
    Sep 11, 2003
Loading...

Share This Page