I want to when I click on a cell on JTable some text changed in a label in JFrame. I write below code; but when I click, the components’ positions are destroyed, and I see a rearranged gui. I didn’t get any exception in log file, too!
The part of code for JTable mouse listener: (x is a JTable)
x.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
try {
String temp = (String) model.getValueAt(x.getSelectedRow(), 0);
Class.forName(Configure.driver);
Connection con = DriverManager.getConnection(Configure.url
+ Configure.dbName, Configure.userName, Configure.password);
java.sql.PreparedStatement prs2 = con.prepareStatement(
"select count(*) as tedad from messages where receiver=?");
prs2.setString(1, temp);
temppResultSet = prs2.executeQuery();
if (temppResultSet.next()) {
int RecNum = temppResultSet.getInt("tedad");
System.out.print("RECEIVED NUM: " + RecNum);
numberOfMessageReceiveByuser.setText("dsdsdsaf");//LABEL NAME
}
} catch (Exception ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
//throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void mousePressed(MouseEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void mouseReleased(MouseEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void mouseEntered(MouseEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void mouseExited(MouseEvent e) {
// throw new UnsupportedOperationException("Not supported yet.");
}
});
the problem solved.
i set all of positioned of my components statically(not with layout manager).
when you want to set positions statically you should set component layout to null with .setLayout(null)
that was the finger note i forget to do!