1

JTableのラベルで変更されたテキストのセルをクリックしたときJFrame。私は以下のコードを書きます。しかし、クリックすると、コンポーネントの位置が破壊され、再配置されたGUIが表示されます。ログファイルにも例外はありませんでした!

マウスリスナーのコードの一部JTable:(xJTable

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.");
    }
});
4

1 に答える 1

0

問題は解決しました。コンポーネントの配置をすべて静的に設定しました(レイアウトマネージャーではありません)。位置を静的に設定する場合は、コンポーネントのレイアウトをnullに設定する必要があります。.setLayout(null)は、忘れてしまった指のメモです。

于 2012-08-16T21:57:53.017 に答える