Results 1 to 9 of 9
- 05-11-2011, 12:15 AM #1
Member
- Join Date
- May 2011
- Posts
- 7
- Rep Power
- 0
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
- 05-11-2011, 12:25 AM #2
Senior Member
- Join Date
- Jan 2011
- Location
- Rizal Province, Philippiines
- Posts
- 167
- Rep Power
- 0
want is jbotton? heheJava Code:int rowCounter = table.getSelectedRow(); int colCounter = table.getSelectedColumn(); String o = (String) table.getModel().getValueAt(rowCounter, colCounter); if(o.equals("")){ }else{ }
- 05-11-2011, 12:34 AM #3
Member
- Join Date
- May 2011
- Posts
- 7
- Rep Power
- 0
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
- 05-11-2011, 12:35 AM #4
Member
- Join Date
- May 2011
- Posts
- 7
- Rep Power
- 0
Sorry to be so beginner
- 05-11-2011, 12:45 AM #5
Senior Member
- Join Date
- Jan 2011
- Location
- Rizal Province, Philippiines
- Posts
- 167
- Rep Power
- 0
can i see the code and the error?
cause i'm lazy to download files hehe
- 05-11-2011, 12:52 AM #6
Member
- Join Date
- May 2011
- Posts
- 7
- Rep Power
- 0
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();
}
}
- 05-11-2011, 12:53 AM #7
Member
- Join Date
- May 2011
- Posts
- 7
- Rep Power
- 0
the values in the jTable are Double, and JSpinner indicate the number of rows.
- 05-11-2011, 01:37 AM #8
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,144
- Rep Power
- 5
- 05-11-2011, 10:58 AM #9
Member
- Join Date
- May 2011
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Array null values
By blug in forum New To JavaReplies: 2Last Post: 03-20-2011, 06:48 AM -
Printing memory addresses and null values
By Ben1 in forum New To JavaReplies: 21Last Post: 10-11-2010, 05:05 PM -
JSP/Ajax/Post giving null values
By Mange in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 04-22-2010, 10:02 PM -
null values
By jabo in forum New To JavaReplies: 3Last Post: 03-31-2010, 03:44 PM -
How to get null values stored in array
By Ms.Ranjan in forum New To JavaReplies: 4Last Post: 05-21-2009, 10:29 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks