1

I'm trying to achieve something similar to this. Live debug text area.

enter image description here

In my case, I have a scrollPanel which has a textArea. I need to run a bunch of SQL queries and output the query and the result one by one.

private JTextArea uploadProcess = new JTextArea();

I click a button to perform the update, and it has a MouseListener with mouseClicked action.

btnFinish.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent arg0) {

      String countNumber = textField.getText();
      String mcu = textField_1.getText();

      if(!countNumber.isEmpty() && !mcu.isEmpty()) {
         if(mcu.length()==12) {
            upload(path, countNumber, mcu,environment[env]);
         }              

      } else {                  
         JOptionPane.showMessageDialog(contentPane,
                     "UPLOAD FAILED!!",
                     "ERROR!",
                     JOptionPane.ERROR_MESSAGE);
      }
    }
});

ps. I know that mouseClicked action is waiting for all the upload method, and then updating.

The upload method:

uploadProcess.setText("Uploading Process Started...\nThere are "+ sqls.size() + " records.\n\n");
Database db = new Database();
db.connect(envo);
int resluts = 0;
for(int i =0; i<sqls.size();i++) {
    resluts = db.updateQuery(sqls.get(i));
    uploadProcess.append("Query #" + i + "\n   " +sqls.get(i));
    uploadProcess.append("\n   " + resluts + " row(s) updated in " + envo);
    sqls.set(i, sqls.get(i) + "  \n " + resluts + " row updated.");
}

Capture2.png

Any help/advice is helpful.

Shank
  • 1,387
  • 11
  • 32
  • What is the problem you are facing? Is that the text area does not update in realtime or is it not updating at all? – Ashwinee K Jha Aug 22 '16 at 19:04
  • 2
    1. Why use a MouseListener instead of an ActionListener? 2. You are blocking up the EDT by running all the queries on the EDT - consider starting your own Thread or using a SwingWorker – copeg Aug 22 '16 at 19:05
  • @AshwineeKJha It is not updating in realtime, it is only updating at the end – Shank Aug 22 '16 at 19:05
  • @copeg I changed it to ActionListener, but its still had the same outcome – Shank Aug 22 '16 at 19:12
  • 1
    Yes, because ActionListener runs its code on the EDT. See the points in my answer [here](http://stackoverflow.com/questions/38953285/when-i-run-my-autoclicker-i-cant-stop-it/38959211#38959211) for ways to avoid locking up the EDT – copeg Aug 22 '16 at 19:13
  • @copeg Okay I got it now, I will try out swingworker – Shank Aug 22 '16 at 19:16
  • 1
    @Shank: for [example](http://stackoverflow.com/a/20603012/230513). – trashgod Aug 22 '16 at 23:47

0 Answers0