Hey guys!
I want to use jtable to encode a grade, this is where i will enter the grade of the student.
and when i click the submit button, the data should be in a variable where i can manipulate it and solve for the average.
It will look like the image below.
soo.. everytime i open that window, the student name and student number will automaticall be in there because when the window opened, i called it already.

This is what i got.:

public SampleModel getSelectedModel(){
        SampleModel myModel = new SampleModel();
        DefaultTableModel dtm = (DefaultTableModel) tblEnterData.getModel();
        Vector data = dtm.getDataVector();
        String name = dtm.getValueAt(tblEnterData.getSelectedRow(), 0).toString();
        String age = dtm.getValueAt(tblEnterData.getSelectedRow(), 1).toString();
        System.out.println("String testing: " +name);

        myModel.setName(name);
        myModel.setAge(age);
        for(int x = 0 ; x <=dtm.getRowCount(); x++){
            for(int y = 0; y <dtm.getColumnCount(); y++){

                System.out.println("data age: "+tblEnterData.getValueAt(x,y).toString());
                System.out.println("data name: "+tblEnterData.getValueAt(y,x).toString());
                /*  String dataArr =   data.get(x).toString();
            String[] naSplit = dataArr.split(",");
              System.out.print("data : "+naSplit[x]);*/
            }
        }

this is just a sample.

what is the actual question you have?

how to get all the data from the table with the button..

there are different ways to do this, depending on the way you want to have the information in.
the getModel(); method is one option.
you can check the JTable api for more options.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.