Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6164445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:59:39+00:00 2026-05-23T21:59:39+00:00

I have written a GUI for operating a card reader – mainly consisting of

  • 0

I have written a GUI for operating a card reader – mainly consisting of an ADD button that brings up a FileChooser dialog and queues the chosen File onto a CardHopper, which is displayed visually as a JList.

Now I want for the CPU (another JFrame, on another thread) to be able to make requests of the card reader; e.g. read a card and send it to me. Before the card reader had a GUI, it was just a model that ran on the same thread as the CPU, so I could just call its readCard() method. Now that it’s on a separate thread, it seems like the right way to communicate is with message-passing.

I was about to implement something using a PriorityBlockingQueue, whereby the CPU would put a read-card command on the queue and the CardReader would take and execute the command, until I realized that the CardReader thread would normally be blocked somewhere within its NetBeans-supplied Swing code, waiting for a GUI event and blind to the arrival of anything on my event queue. Moreover, this “back end” request would alter the data model – so even if I could somehow execute some code in the model, would it be kosher to “fire” notifications to the GUI’s ListDataListeners while the GUI is waiting for GUI events?

I hope this isn’t too cryptic – I’m still trying to get my arms around the mechanics of GUIs and threads.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:59:40+00:00Added an answer on May 23, 2026 at 9:59 pm

    Would it be kosher to “fire” notifications to the GUI’s
    ListDataListeners while the GUI is waiting for GUI events?

    Absolutely not.

    What you want to do is perform all tasks that directly manipulate your UI’s models (or call UI functions) on the Swing event thread.

    Essentially, when you’re ready to post an event that will perform some UI task, do it like:

    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
         ...
      }
    }
    

    You can fire all your listeners, and do whatever you want to your ListModel (or your other UI models) there since it will only get run in the Swing thread.

    Otherwise, you risk Swing trying to read you data while it is painting and you are updating your data. You’ll start getting NullPointerException, ArrayIndexOutOfBoundExceptions, ConcurrentModifictionException, etc.

    Ideally, you would perform all of your background work in a separate thread (or under SwingWorker), and then when everything is ready, push an update via invokeLater.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a small GUI based vb.net program that speaks to embedded devices
I have a simple GUI component written in Java. The class draws an analog
I have written an AIR Application that downloads videos and documents from a server.
I have written a DLL that uses MS Word to spell check the content
I have written something that uses the following includes: #include <math.h> #include <time.h> #include
I have written a watir script that downloads files. One of the files it
I have a windows service written in C# that acts as a proxy for
I have written an image processing application with the GUI part written in Java
I have a GUI written using netbeans with a few simple components in place.
I have written a persistent windows service in java that runs on boot. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.