Results 1 to 9 of 9
  1. #1
    aviolently is offline Member
    Join Date
    Jun 2011
    Posts
    23
    Rep Power
    0

    Default Help here in GUI using JTable reading a text file to be inputed in the Table!

    Hello someone help me in my program...

    Im using JCREATor.

    i dont know how to input data from a text file reading it to be inputed in GUI using JTable..

    i already created the Table and here is my code!
    Java Code:
    import javax.swing.*;
    import java.awt.*;
    
    
    public class StudentView extends JFrame{
    	JTable studentTable;
    	JButton addStudentButton,
    		deleteStudentButton,
    		editStudentButton;
    
    	public StudentView(String title) {
    		super(title);
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    
    
    		JPanel mainPanel = new JPanel(new BorderLayout());
    		JPanel buttonPanel = new JPanel(new GridLayout(1,3, 20, 20));
    
    		mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    
    		studentTable = new JTable(10, 5);
    
    
    
    		addStudentButton = new JButton("Add");
    		deleteStudentButton = new JButton("Delete");
    		editStudentButton = new JButton("Edit");
    
    
    		buttonPanel.add(addStudentButton);
    		buttonPanel.add(deleteStudentButton);
    		buttonPanel.add(editStudentButton);
    
    		mainPanel.add(BorderLayout.CENTER, studentTable);
    		mainPanel.add(BorderLayout.SOUTH,  buttonPanel);
    
    		setContentPane(mainPanel);
    	}
    	public static void main(String [] args){
    		StudentView f=new StudentView("Students Record");
    		f.setVisible(true);
    		f.pack();
    	}
    
    
    
    }
    i dont know how to input the data from a text file to each collumn.....
    and i dont know what to do the next one....
    Last edited by JosAH; 06-27-2011 at 10:16 AM. Reason: Fixed the [code] ... [/code] tags

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,023
    Blog Entries
    7
    Rep Power
    20

    Default

    Read the API documentation for the TableModel (interface) and the DefaultTableModel (class). The file reading part is an entirely different issue ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    aviolently is offline Member
    Join Date
    Jun 2011
    Posts
    23
    Rep Power
    0

    Default

    ohh ill try sir..i think i need to create a new class to be inherited to this program!!

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,023
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by aviolently View Post
    ohh ill try sir..i think i need to create a new class to be inherited to this program!!
    No you don't (for now); simply create a DefaultTableModel, fill it with your data and pass it to your JTable.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    aviolently is offline Member
    Join Date
    Jun 2011
    Posts
    23
    Rep Power
    0

    Default

    can someone help me in doing it and add it to my codes....this thing is killing me .....WTF!!!

  6. #6
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    It depends on where you are getting your information to put in the table. If its from a file you need to look into IO.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  7. #7
    aviolently is offline Member
    Join Date
    Jun 2011
    Posts
    23
    Rep Power
    0

    Default

    i cant really do it..... how make a class that would read a text file (note pad) to be inputed in an array.....some one provide me codes/.... ive tried for 3 hours making but i cant do it...error ...error... error...some one provide code or example please.....please......

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,023
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by aviolently View Post
    i cant really do it..... how make a class that would read a text file (note pad) to be inputed in an array.....some one provide me codes/.... ive tried for 3 hours making but i cant do it...error ...error... error...some one provide code or example please.....please......
    Begging is so pathetic; if you really can't do it, maybe the conclusion must be that programming is not for you; and, b.t.w. three hours isn't that much time ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

Similar Threads

  1. Reading from file and adding to JTable
    By purple in forum New To Java
    Replies: 11
    Last Post: 04-14-2011, 10:33 PM
  2. Writing and Reading data to and from xml file to JTable
    By ramihemang90 in forum Advanced Java
    Replies: 3
    Last Post: 03-15-2011, 02:07 PM
  3. Conveting a Text File to a Table
    By tudorH in forum JDBC
    Replies: 8
    Last Post: 02-26-2010, 06:41 AM
  4. Replies: 6
    Last Post: 12-12-2008, 03:35 PM
  5. Replies: 1
    Last Post: 08-07-2007, 05:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •