Results 1 to 2 of 2
  1. #1
    doha786 is offline Member
    Join Date
    Mar 2009
    Rep Power

    Arrow need a loop to add new row(s)

    hi, i am trying to build a simple program where system asking info (name,age,sex & location) to make a table using do-while loop.

    for each info will create one new row in table that i dont know how to make..

    please help me...

    here, i made for one single row only:
    Java Code:
     public static void main (String args[])
    	String name, age, sex, location, ans;
    	Scanner scanner=new Scanner(;
     	do {
    	System.out.print("Name: ");;
    	System.out.print("Age: ");;
    	System.out.print("Gender: ");;
    	System.out.print("Location: ");;
    	System.out.print("Do you want another input??  YES / NO:") ;;
    	while (ans.equals("YES")); 
    		System.out.print("Here is the full data");
    	JFrame frame=new JFrame("TABLE");
    	JPanel panel=new JPanel();
    	panel.setLayout(new BorderLayout());
    	DefaultTableModel model= new DefaultTableModel();
      Vector<String> vCol = new Vector<String>();
    vCol.addElement("Name"); 	vCol.addElement("Age");  	 vCol.addElement("Sex");   	vCol.addElement("Location");
     Vector<String> row= new Vector<String>();
    row.addElement(name);        row.addElement(age); 
    row.addElement(sex);           row.addElement(location);
    Vector<Vector> vRow=new Vector<Vector>();
    		model = new DefaultTableModel(vRow, vCol); 
    		JTable table = new JTable(model);
         	JScrollPane	scrollpane = new JScrollPane(table);
         panel.add(scrollpane, BorderLayout.CENTER);

  2. #2
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Rep Power

Similar Threads

  1. for loop help
    By soc86 in forum New To Java
    Replies: 9
    Last Post: 01-24-2011, 10:45 PM
  2. using for loop...pls help
    By in forum Eclipse
    Replies: 2
    Last Post: 12-13-2009, 10:30 AM
  3. do while loop?
    By shroomiin in forum New To Java
    Replies: 2
    Last Post: 11-13-2009, 11:32 AM
  4. while-loop stopping on first loop
    By davester in forum New To Java
    Replies: 6
    Last Post: 06-26-2009, 08:46 PM
  5. can you help me with this for loop?
    By java_fun2007 in forum New To Java
    Replies: 6
    Last Post: 12-22-2007, 11:20 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