Results 1 to 9 of 9
  1. #1
    felipin85 is offline Member
    Join Date
    May 2011
    Posts
    7
    Rep Power
    0

    Exclamation JTable write in the file values null

    Hi, I'm making the interface with Netbeans. I have JTable, for the user will put values in the five columns and various rows. The user enters values ​​in the JTable, and then he pressing a JBotton to write in a file the values. But, If the user does not click on a blank cell after entering the last value. I don't know how to fix this. The jBotton is seven.


    Thanks and Regards
    Attached Files Attached Files

  2. #2
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default

    Java Code:
    int rowCounter = table.getSelectedRow();
    int colCounter = table.getSelectedColumn();
    
    String o = (String) table.getModel().getValueAt(rowCounter, colCounter);
    if(o.equals("")){
    
    }else{
    
    }
    want is jbotton? hehe

  3. #3
    felipin85 is offline Member
    Join Date
    May 2011
    Posts
    7
    Rep Power
    0

    Default

    Thanks RichersooN, but, I still have the same problem, where I have to add those lines, I tried it on several sites and get the same thing.
    The line starts jBotton 2381.

    Thanks and Regards

  4. #4
    felipin85 is offline Member
    Join Date
    May 2011
    Posts
    7
    Rep Power
    0

    Default

    Sorry to be so beginner

  5. #5
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default

    can i see the code and the error?
    cause i'm lazy to download files hehe

  6. #6
    felipin85 is offline Member
    Join Date
    May 2011
    Posts
    7
    Rep Power
    0

    Default

    hehe, Don't worry. The code is:

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:

    int i=0;
    this.cargas=Integer.parseInt(this.jSpinner1.getVal ue().toString());
    /*
    this.cargas=Integer.parseInt(this.jSpinner1.getVal ue().toString());
    //Escribir todos los datos de la tabla a un fichero de datos
    this.xc=(Double)jTable1.getValueAt(0,0);//Opción uno si lo que guarda es un float, double o long, habría que mirar que tipo quieres en realidad
    this.yc=(Double)jTable1.getValueAt(0,1); //Opción dos si lo que guarda en realidad es la string
    this.a= (Double)jTable1.getValueAt(0,2);
    this.b=(Double)jTable1.getValueAt(0,3);
    this.cargaspilares =(Double)jTable1.getValueAt(0,4);
    System.out.println(this.xc);
    System.out.println(this.yc);
    System.out.println(this.a);
    System.out.println(this.b);
    System.out.println(this.cargaspilares);
    System.out.println(this.cargas);
    */


    try
    {
    // nombrearchivocargas=CampoTextoCargas.getText();
    //System.out.println(nombrearchivocargas);
    // nombrearchivo="/home/CC.dat"; //copio la ruta
    FileWriter fichero = new FileWriter("/home/Placas/cargas.dat"); //Si ponemos true, lo que hace es añadir un
    PrintWriter pw = new PrintWriter(fichero);
    this.cargas=Integer.parseInt(this.jSpinner1.getVal ue().toString());
    pw.println(this.cargas);
    for (i=0;i<cargas;i++){
    /*
    xc=jTable1.getAtValue(1,i);
    yc=jTable1.getAtValue(2,i);
    a= jTable1.getAtValue(3,i);
    b=jTable1.getAtValue(4,i);
    cargapilar=jTable1.getAtValue(5,i);

    xc=(Double)jTable1.getValueAt(1,1);//Opción uno si lo que guarda es un float, double o long, habría que mirar que tipo quieres en realidad
    yc=(Double)jTable1.getValueAt(1,2); //Opción dos si lo que guarda en realidad es la string
    a= (Double)jTable1.getValueAt(1,3);
    b=(Double)jTable1.getValueAt(1,4);
    cargapilar =(Double)jTable1.getValueAt(1,5);
    System.out.println(xc);
    System.out.println(yc);
    System.out.println(a);
    System.out.println(b);
    System.out.println(cargapilar);
    */

    //Escribir todos los datos de la tabla a un fichero de datos
    this.xc=(Double)jTable1.getValueAt(i,0);//Opción uno si lo que guarda es un float, double o long, habría que mirar que tipo quieres en realidad
    this.yc=(Double)jTable1.getValueAt(i,1); //Opción dos si lo que guarda en realidad es la string
    this.a= (Double)jTable1.getValueAt(i,2);
    this.b=(Double)jTable1.getValueAt(i,3);
    this.cargaspilares =(Double)jTable1.getValueAt(i,4);
    //Para arreglar el problema de que escriba null
    int rowCounter = jTable1.getSelectedRow();
    int colCounter = jTable1.getSelectedColumn();
    String o = (String)jTable1.getModel().getValueAt(rowCounter, colCounter);
    /* System.out.println("estoy aqui");
    System.out.println(this.xc);
    System.out.println(this.yc);
    System.out.println(this.a);
    System.out.println(this.b);
    System.out.println(this.cargaspilares);
    System.out.println(this.cargas);*/
    pw.println(this.xc+" "+this.yc+" "+this.a+" "+this.b+" "+this.cargaspilares);


    }

    // pw.println(this.xc,this.yc,this.a,this.b,this.carg aspilares);
    pw.close();
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }


    }

  7. #7
    felipin85 is offline Member
    Join Date
    May 2011
    Posts
    7
    Rep Power
    0

    Default

    the values in the jTable are Double, and JSpinner indicate the number of rows.

  8. #8
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

  9. #9
    felipin85 is offline Member
    Join Date
    May 2011
    Posts
    7
    Rep Power
    0

    Default

    Thanks Camickr, I have tried to put the code, but does not do what I want. I think what I want to do the link you put, you can not. You always have to press the enter the user when entering a figure?
    Thanks

Similar Threads

  1. Array null values
    By blug in forum New To Java
    Replies: 2
    Last Post: 03-20-2011, 06:48 AM
  2. Printing memory addresses and null values
    By Ben1 in forum New To Java
    Replies: 21
    Last Post: 10-11-2010, 05:05 PM
  3. JSP/Ajax/Post giving null values
    By Mange in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 04-22-2010, 10:02 PM
  4. null values
    By jabo in forum New To Java
    Replies: 3
    Last Post: 03-31-2010, 03:44 PM
  5. How to get null values stored in array
    By Ms.Ranjan in forum New To Java
    Replies: 4
    Last Post: 05-21-2009, 10:29 PM

Tags for this Thread

Posting Permissions

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