Java 在GUI中显示DefaultTableModel中的所有模拟值,而不仅仅是最后一个

Java 在GUI中显示DefaultTableModel中的所有模拟值,而不仅仅是最后一个,java,swing,jtable,Java,Swing,Jtable,我试图显示从插座接收的血压模拟器的所有模拟值 The UserID sent from the socket was: 1 The SystolicBP sent from the socket was: 9 The DiastolicBP sent from the socket was: 6 The UserID sent from the socket was: 2 The SystolicBP sent from the socket was: 11 The DiastolicBP

我试图显示从插座接收的血压模拟器的所有模拟值

The UserID  sent from the socket was: 1
The SystolicBP sent from the socket was: 9
The DiastolicBP sent from the socket was: 6
The UserID  sent from the socket was: 2
The SystolicBP sent from the socket was: 11
The DiastolicBP sent from the socket was: 9
The UserID  sent from the socket was: 3
The SystolicBP sent from the socket was: 18
The DiastolicBP sent from the socket was: 14
The UserID  sent from the socket was: 4
The SystolicBP sent from the socket was: 15
The DiastolicBP sent from the socket was: 12
The UserID  sent from the socket was: 5
The SystolicBP sent from the socket was: 19
The DiastolicBP sent from the socket was: 16
The UserID  sent from the socket was: 6
The SystolicBP sent from the socket was: 14
The DiastolicBP sent from the socket was: 11
The UserID  sent from the socket was: 7
The SystolicBP sent from the socket was: 19
The DiastolicBP sent from the socket was: 16
但是尝试使用DefaultTableModel来显示它

private void DisplayActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
    
      model.insertRow(model.getRowCount(),new Object[]{this.getBPMSUserID(),this.getBPMSSystolicBP(),this.getBPMSDiastolicBP()});
我只得到表中最后一个模拟值 71916


如何显示它们呢?

好吧,您需要调用多个
insertRow(…)
语句。如果只得到一行,则表示1)只添加一行,或2)每次插入行之前创建一个新模型。您发布的代码与问题无关。这个问题包含在代码的其他地方。底线是您需要多次调用上述方法。另外,为什么代码包含在ActionEvent中?如果您从套接字获取数据,那么从套接字读取数据的代码应该直接调用一个方法,将每行数据添加到TableModel中。此外,方法名称不应该以大写字符开头!不要在评论中发布代码。它不可读。InputStream InputStream=socket.getInputStream();DataInputStream DataInputStream=新的DataInputStream(inputStream);而(true){for(int i=1;i<8;i++){BPMSUserID=dataInputStream.readInt();bpmsystolicbp=dataInputStream.readInt();BPMSDiastolicBP=dataInputStream.readInt();System.out.println(“从套接字发送的用户ID是:“+BPMSUserID”);……}我想通过显示按钮和DefaultTableModel将打印在System.Output中的信息传递到GUI。