1

我想当我单击某个JTable在标签中更改的文本上的单元格时JFrame。我写下面的代码;但是当我点击时,组件的位置被破坏了,我看到了一个重新排列的 gui。我在日志文件中也没有任何异常!

JTable鼠标侦听器的代码部分: ( xis 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.");
    }
});
4

1 回答 1

0

问题解决了。我静态设置了我的组件的所有位置(不是使用布局管理器)。当您想静态设置位置时,您应该使用 .setLayout(null) 将组件布局设置为 null,这是我忘记做的手指注释!

于 2012-08-16T21:57:53.017 回答