Adding wait method to a JTable <p>Edited - To clarify what my problem was I have decided to edit this. </p> <p>My problem involved the method below:</p> <pre><code>addTransactionButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ AllGUI allGUI = new AllGUI(); allGUI.createAllGUI(); TCRSpecificGUI tcrGUI = new TCRSpecificGUI(); tcrGUI.getNtryName(); dtm.addRow(new Object[]{TCRSpecificGUI.ntryName,AllGUI.bankTransCode,TCRSpecificGUI.endToEndId, AllGUI.transAmount,AllGUI.initiatingPartyId,AllGUI.initiatingPartySchemeName, AllGUI.debtorName,AllGUI.debtorAddress,TCRSpecificGUI.debtorAccountType, TCRSpecificGUI.creditorAccountNumber,TCRSpecificGUI.proprietaryPartyType,AllGUI.debtorAgentName, AllGUI.debtorAgentCity,AllGUI.debtorAgentCountrySubDvsn,AllGUI.creditorAgentClearingSystemId, TCRSpecificGUI.purpose,TCRSpecificGUI.returnRejectReasonCode,TCRSpecificGUI.returnRejectReasonAdditionalInfo, AllGUI.payInstrument,AllGUI.typeOfCheck,AllGUI.passThruData,AllGUI.clearingAccount, AllGUI.jobId,TCRSpecificGUI.nachaTransactionCode,AllGUI.transactionType, TCRSpecificGUI.auxillaryOnUsIndicator,TCRSpecificGUI.batchTypeFromSourceSystem, TCRSpecificGUI.expressMailItem,TCRSpecificGUI.returnOccurance,TCRSpecificGUI.nameOfRMessageFile}); } }); </code></pre> <p>What is occurring there is that a GUI is being called first with the allGUI.createAllGUI() method. This is a JFrame with multiple JTextAreas for the user to fill out. Once the user clicks a confirm button on the first GUI a second one appears with more fields. When a user confirms each of the GUI's all the JTextArea information is saved into Strings and is then written into a JTable as a new row. (As seen above).</p> <p>The problem is that the logic above meant that the program would move to the dtm.addRow step even before the user had completed editing the text fields in the GUI. This means that the first row of the table would be totally blank (as the GUI fields had not yet been saved to strings).</p> <p>In short, the problem is that I needed some way to tell the program "Don't call the addRow code until the user has clicked the confirm button in the allGUI.createALLGUI() method second GUI.</p> <p>I finally found a solution. Since some users decided to mark this question as a "null pointer" duplicate I will just have to post my answer in the body here and then hopefully if the question is reopened I can post as answer.</p> <p>My solution was to move the addRow method into it's own class like this: </p> <pre><code>protected static void writeRow(){ dtm.addRow(new Object[]{TCRSpecificGUI.ntryName,AllGUI.bankTransCode,TCRSpecificGUI.endToEndId, AllGUI.transAmount,AllGUI.initiatingPartyId,AllGUI.initiatingPartySchemeName, AllGUI.debtorName,AllGUI.debtorAddress,TCRSpecificGUI.debtorAccountType, TCRSpecificGUI.creditorAccountNumber,TCRSpecificGUI.proprietaryPartyType,AllGUI.debtorAgentName, AllGUI.debtorAgentCity,AllGUI.debtorAgentCountrySubDvsn,AllGUI.creditorAgentClearingSystemId, TCRSpecificGUI.purpose,TCRSpecificGUI.returnRejectReasonCode,TCRSpecificGUI.returnRejectReasonAdditionalInfo, AllGUI.payInstrument,AllGUI.typeOfCheck,AllGUI.passThruData,AllGUI.clearingAccount, AllGUI.jobId,TCRSpecificGUI.nachaTransactionCode,AllGUI.transactionType, TCRSpecificGUI.auxillaryOnUsIndicator,TCRSpecificGUI.batchTypeFromSourceSystem, TCRSpecificGUI.expressMailItem,TCRSpecificGUI.returnOccurance,TCRSpecificGUI.nameOfRMessageFile}); } </code></pre> <p>leaving the original code like so:</p> <pre><code>addTransactionButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ AllGUI allGUI = new AllGUI(); allGUI.createAllGUI(); TCRSpecificGUI tcrGUI = new TCRSpecificGUI(); tcrGUI.getNtryName(); } }); </code></pre> <p>Finally in the last stage of my GUI where the user fills out the JTextFields I added this:</p> <pre><code>confirmButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ endToEndId=endToEndIdText.getText(); if(checkingButton.isSelected()){ debtorAccountType="Checking"; }else{ debtorAccountType="Savings"; } creditorAccountNumber=creditorAccountNumberCombo.getSelectedItem().toString(); proprietaryPartyType=proprietaryPartyTypeText.getText(); purpose=purposeText.getText(); returnRejectReasonCode=returnRejectReasonCodeText.getText(); returnRejectReasonAdditionalInfo=returnRejectReasonAdditionalInfoText.getText(); nachaTransactionCode=nachaTransactionCodeText.getText(); if(yesAuxillaryButton.isSelected()){ auxillaryOnUsIndicator="YES"; }else{ auxillaryOnUsIndicator="NO"; } batchTypeFromSourceSystem=batchTypeFromSourceSystemText.getText(); if(yesExpressButton.isSelected()){ expressMailItem="YES"; }else{ expressMailItem="NO"; } returnOccurance=returnOccuranceText.getText(); nameOfRMessageFile=nameOfRMessageFileText.getText(); Component component = (Component)ae.getSource(); Window window = SwingUtilities.windowForComponent(component); window.dispose(); TCRMainGUI.writeRow(); } }); </code></pre> <p>Note at the very bottom this line of code:</p> <pre><code>TCRMainGUI.writeRow(); </code></pre> <p>That calls the method to write a new row. </p> <p>So I now have a logic that 1. When a user clicks the create transaction button on the main JTable screen the first GUI class is opened. 2. Once the user fills out the fields and clicks confirm the values are saved to Strings and the next GUI opens. 3. Once the user fills out the fields on the second GUI and clicks confirm the values are saved and the method to add a row is called - The Strings are now populated so the row will be written with the values. </p>