Results 1 to 2 of 2
  1. #1
    cprovos2 is offline Member
    Join Date
    Oct 2012
    Rep Power

    Default Updating text area according to system time thread

    I am writing a program to log and display data through a serial port. I can display what ports are available and read information from them. I am going to be using this to read data from Arduino as well as DAQs. I am unable to display the data continuously inside of my jtextarea. I have a clock that displays the system time and every time it increments I want to display the time and the data being received in the text area. This is jtextarea1 in my code. Jtextarea2 is simply for displaying test information. If anyone knows how I could update my textarea this way please let me know. I already have a thread running for my clock. I want the text area to update while the clock is running. I am unable to use t.isAlive() as a parameter in my while loop... not sure why. Here are a couple sections of my code to give you a general idea. This is my first time using netbeans.

    This is the action performed for my start button that begins the clock and everything else. I indicated in a comment where my while loop is that is not appending to the text area. Without the while loop I will only get one line of data, but with the loop my program crashes:
    Java Code:
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            String COMPort = jTextField2.getText();
            String BaudRate = jTextField3.getText();
            jTextArea2.append("Serial Port: " + COMPort +"\n");
            jTextArea2.append("Baud Rate: " + BaudRate + "\n");
            byte[] buffer;
            while(serialPort.isOpened() == true){ // problem is here
            try {
                buffer = serialPort.readBytes(10);
                jTextArea1.append(buffer + "\n");
            } catch (SerialPortException ex) {
               jTextArea2.append("Serial Port Error");

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Updating text area according to system time thread

    Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)
    Code Conventions for the Java Programming Language -- variable names should start with a lowercase letter

    Not a NetBeans question, moving to AWT/Swing.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Full Time Java Engineers in the Chicago area Apply
    By recruitht in forum Jobs Offered
    Replies: 0
    Last Post: 09-18-2012, 06:12 PM
  2. adding text to a text area dynamically
    By tom2zip in forum AWT / Swing
    Replies: 3
    Last Post: 01-17-2012, 05:58 AM
  3. Replies: 8
    Last Post: 07-17-2011, 02:38 PM
  4. Replies: 0
    Last Post: 12-09-2010, 05:56 PM
  5. Replies: 0
    Last Post: 09-28-2010, 09:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts