aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Column value is getting reset to zero automatically in Jtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Column value is getting reset to zero automatically in Jtable" Watch "Column value is getting reset to zero automatically in Jtable" New topic
Author

Column value is getting reset to zero automatically in Jtable

Gokulakannan Vasu
Greenhorn

Joined: Jan 11, 2011
Posts: 14
In my window,i have certain combo boxes which has dynamic values fetched from database.In particular,i have an 'ADD' button which i clicked will show a window having only a combobox with dynamic values.with actual scenario,if we select any value from that combobox,a row with 3 columns will be created with 1st column being the selected value from the combo box and the other two being zeros.I can give values to the other two columns(integer values only).After entering the value of 3rd row,3rd column when i added another value from the combo box by clicking the 'ADD' button,it creates another row with 3 cols(samething as i said previously).But the value of 3rd row & 3rd column automatically changes to zero.

Please help me to resolve this problem.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2095
    
    7
Post your SSCCE demonstrating the problem.
Gokulakannan Vasu
Greenhorn

Joined: Jan 11, 2011
Posts: 14
1. Assume a combo box which has dynamic values fetched from database.If you select any of the value,a row will be created with 3 cols.
2. Follow it for all the values in the combo-box

Please see the attachment for table structure.

3. When i followed the same step for entering 4th column,the cell value of 3X3(3rd row,3rd column) automatically becomes zero.
Gokulakannan Vasu
Greenhorn

Joined: Jan 11, 2011
Posts: 14
Attachment are here.Kindly download the attachments.



[Thumbnail for Table format.JPG]


[Thumbnail for errorpage.JPG]

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2095
    
    7
I don't see a SSCCE anywhere...
Gokulakannan Vasu
Greenhorn

Joined: Jan 11, 2011
Posts: 14
@ Mr.Rob Camick

Could you please tell me,what you exactly need from me.I can do it precisely for you to understand correctly.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2095
    
    7
Read the link provide and post the simple code that demonstrates the problem.
Gokulakannan Vasu
Greenhorn

Joined: Jan 11, 2011
Posts: 14
1. Combobox having values A,B,C,D,E etc (dynamic values from Database).If you select 'A',one row will be created as follows

Value selected from Combobox Percent No of items
A 67 43

2. We can create any number of rows,until the combo box value becomes empty(as it it dynamic).

3. When i tried to create 4th row,the row is created but the cell value of 3rd row,3rd column automatically reset to zero.

4. Its working fine for the next rows.The error is with 3rd row.The loops and conditions are generic.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9995
    
    7

This is a link => http://sscce.org/
Click on it.
Read it and understand what Rob is meaning when he says SSCCE.
Then post your code which demonstrates the problem.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Gokulakannan Vasu
Greenhorn

Joined: Jan 11, 2011
Posts: 14
This method gives the values in the combobox.once you selected a value in the combo,the left value will be calculated

EventHandler:
if (selectedValue != null) {
ThresholdStatistics stat = new ThresholdStatistics(detailedThreshold, selectedValue); /* detailedThreshold - value from the bean file,selectedValue - value selected from the combo */
getStatisticsTableModel().addStatistics(stat);/* Add a new row */

}
}
TableModel:

public void addStatistics(ThresholdStatistics stat) {
rows.addElement(stat);
count++;
fireModelChanged(new TableModelEvent(this,
rows.size()-1,
rows.size()-1,
TableModelEvent.ALL_COLUMNS,
TableModelEvent.INSERT));
}

ModelFile:

public static String[] getStatsLeftForThreshold(ThresholdDetailData threshold) {
Vector stats = null;
for (int i=0; i<StatsByThresholdTypes.length; i++) { /* StatsByThresholdTypes - dynamic values in the combobox
if (StatsByThresholdTypes[i][0].equals(threshold.getTypeCode())) {
stats = new Vector(StatsByThresholdTypes[i].length);
for (int j=1; j<StatsByThresholdTypes[i].length; j++) {
if (!isStatPresentInThreahold(threshold, StatsByThresholdTypes[i][j])) {
stats.addElement(StatsByThresholdTypes[i][j]);
}
}
i = StatsByThresholdTypes.length;
}
}
if (stats == null || stats.size() == 0) {
return null;
}
else {
String statStrings[] = new String[stats.size()];
for (int i=0; i<statStrings.length; i++) {
statStrings[i] = (String)stats.elementAt(i);
}
return statStrings;
}
}
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9995
    
    7

Did you even bother to read the contents of the link?
From the SSCCE page,

It is important to ensure that the code you relate to others can be 'copied, pasted, compiled, run' so that they can help you quickly and with a minimum of fuss.
This means that after the code has been copied, pasted and compiled by those helping you, they can run it and see the results for themselves...

The code you have posted, does it meet this criteria? Do you understand all the points given on the SSCCE page?
Gokulakannan Vasu
Greenhorn

Joined: Jan 11, 2011
Posts: 14
I am very sorry that i cant deliver any code over here,as its a violation.Also it involves MVC architechture,wherein i need to send you all client.model & server codes.

Can you please suggest me why this problem exists atleast.If you want any more explanation i am ready to explain you in brief.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2095
    
    7
wherein i need to send you all client.model & server codes.


No. That is the point of creating a SSCCE. We DON'T want to see you client/server code. We want you to post a simple example that demonstrates the problem. Your problem is with a JTable not the client/server connection. You can just hard code the data in the table.

Can you please suggest me why this problem exists atleast.


Have you tried the example from the Swing tutorial. The code found there works perfectly. So the problem is with your code. We are not mind readers we can't guess why your code is different than the code from the tutorials. So if you want help you need to make the effort to create a SSCCe.
Gokulakannan Vasu
Greenhorn

Joined: Jan 11, 2011
Posts: 14
@Rob Camick
if you want help you need to make the effort to create a SSCCe.


Sure dude...This is the first time i am into this.Surely i will correct my faults...!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Column value is getting reset to zero automatically in Jtable
 
Similar Threads
JCOMBO Box traversal problem
Swing JCombobox and JTable issue
MultiComponent JTable
How to Update multiple rows of a table in jsp
JSP- finding the table row selected