3 Replies Latest reply: Sep 5, 2012 4:13 PM by jduprez RSS

    Inserting Custom object in JTable

      Hi All

      I am new to JAVA.

      I am trying to insert custom data to JTable.

      I have a class called Student with some instance fields(like Name,age,sex ), and I want to add object of Student type to JTable.
      In table I want to display Student class fields. I have extended a class StudentModel from AbstractTableModel.My StudentModel
      contains a Vector to keep student data.

      But how do I add student object to StudentModel.and display in JTable

      please help

      thanks in advance
        • 1. Re: Inserting Custom object in JTable
          You call the method of StudentModel which takes a Student as its parameter and is designed to add a Student to the model.

          You did write a method like that, didn't you? If you didn't, then you should.
          • 2. Re: Inserting Custom object in JTable
            I did add a method to get Student type but while compiling it shows error.

            the method which i added in Student model class is given below

            public void addStudent( Student stud ){

            • 3. Re: Inserting Custom object in JTable
              apparently your problem is not related to Swing but to learning the Java language.

              If your aim is to learn Java, you should tackle this compile error. For that I suggest you turn to a colleague or a fellow student... or continue here, but you need to give more code than just the bit that doesn't compile.
              If your aim is to make the darn program display students in a JTable, you can have a look at BeanTableModel (http://tips4java.wordpress.com/2008/11/27/bean-table-model/).

              Best regards,