Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with Table.getSelectedColumn() method plz help its so urgent  RSS feed

 
Suresh nadarajan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to display a input msg box while the given icode( coloumn name) is not there in database and the the input value should goto the product( 3rd column in my table) column in table. my code is bellow.

private void TablePropertyChange(java.beans.PropertyChangeEvent evt) {

// ss
i=0;
int s=1;
String icde=new String();
String Prdct=new String();
String result=new String();
// String CODE=new String();
String ICDE=new String();
String prd=new String();
int Colselected=Table.getSelectedColumn();
//column.getPreferredWidth();
try
{
TableColumn ICode = Table.getColumnModel().getColumn(1);
TableColumn product = Table.getColumnModel().getColumn(2);
TableColumn unit = Table.getColumnModel().getColumn(3);
TableColumn rate = Table.getColumnModel().getColumn(4);
TableColumn Amount = Table.getColumnModel().getColumn(5);



for(;i<s;++i)
{
//For loop starts

ICode.setPreferredWidth(76);
product.setPreferredWidth(157);
unit.setPreferredWidth(75);
rate.setPreferredWidth(85);
Amount.setPreferredWidth(95);
Table.setValueAt(i+1,i,0);

float gr=0,//Gross amt
qt=0,//Qty
rt=0,//Rate;
dcp=0,//Disc%
dcam=0,//Disc Amt
edrt=0,//EDrate
edrt1=0,
edam=0,//EDGross
taxrt=0,//TaxRate
taxam=0,//TaxAmt
netam=0;//netamt

try
{

Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

Connection con1 = DriverManager.getConnection(url1,"suresh", "special");
Statement stmt1 = con1.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);

Prdct=Table.getValueAt(i,1).toString();
Statement stmti= con1.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rsi = stmti.executeQuery("select * from prd where ICODE='"+Prdct+"'");
java.util.Vector ><String> prdct = new java.util.Vector <String>();
if(rsi.next())
{
String prodct=rsi.getString("ITEM");
prdct.add(prodct);
Table.setValueAt(prdct,i,1);

Double RT=rsi.getDouble("saleprice");
String RTS=RT.toString();
Table.setValueAt(RTS,i,4);

}
// int ColValue=Colselected==1;
else if(Colselected==1)
{
result = (String)JOptionPane.showInputDialog(this,
"Enter the new Item", "S-appsys's INFO",JOptionPane.INFORMATION_MESSAGE);
System.out.println("asdrf "+i);
Table.setValueAt(result,i,2);
// Colselected=0;
// Table.setV
// System.out.println("asdrf "+i);

}// Table.setValueAt(result,i,2);

}catch ( java.lang.ClassNotFoundException cl)
{
System.out.println("Error"+cl);
}
catch(java.sql.SQLException sq)
{
System.out.println("Error"+sq);
}



qt=Float.parseFloat(Table.getValueAt(i, 3).toString());
rt=Float.parseFloat(Table.getValueAt(i, 4).toString());
gr=qt*rt;

Table.setValueAt(gr,i,5);

s=Table.getRowCount();

}

}catch(java.lang.NullPointerException e){}


}



my problem is i can get the msg box while i am giving value in 1st time. but if i am giving the value in second row it will show the msgbox 4 times and it will change previous rows product column value twise and then it will change current row value. i need solution for this

plzzz help me

Thanks in advance
Suresh.
 
shansi raj
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im afraid whether i could understand ur question properly. But anyways it seems that you need a alert msg displayed if the second column is empty.
Have a mouse released or mouse pressed function and then check whether the 2nd column is empty and alert a msg. Also remove the setPreferredWidth and place it outside the loop.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!