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 7165995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:20:29+00:00 2026-05-28T14:20:29+00:00

I’m writing a 2D polygon and physics editor, one functionality is to set a

  • 0

I’m writing a 2D polygon and physics editor, one functionality is to set a rotation limit for joints.

To use this functionality, the user clicks and drags a line between the joint points which need to receive the limit.

The logic of determining if the pick is valid happens outside of the GUI code.

If a pick is found, I wanted to pop up a JOptionPane.showInputDialog where the user can input the limit.

Thing is, if I do it directly, the program becomes unresponsive, I figure it’s because of threading.

I’s there a way to define an event listener the GUI can use that doesn’t require an actual GUI component?

I want to send an event that also contains a reference to the target object to that component, then telling it that a valid pick has been made and user input is required, and then send the value back via a method of the target object.

I am very inexperienced with Swing.
My hunch is that I might be able to add an ActionListener to the main window, but I don’t know how I could address that listener specifically.
As in, how would I need to define an Action that only gets processed by that particular listener?
If that is actually possible, of course.

So far I have only used listeners to let the GUI talk to the logic, not the other way around…

Edit:
The program becomes unresponsive the movement I call
result = JOptionPane.showInputDialog(this,"Enter Limit.");

That just breaks it. Can’t even enter anything into the textbox, nor close it, etc.

I figure it’s because it spawns a modal dialog that pauses some thread, and calling it from somewhere in the bowels of non GUI code is just not the thing I should do, but I’m too inexperienced to know another way…

Edit2:
I should add that I can use JOptionPane.showInputDialog without any problems if I spawn it, for example, after clicking a button or choosing a popup menu option.
In fact that’s how I rename the items I am working with.

But I assume at that point, the dialog is being spawned inside the GUI thread, or this Event Dispatcher queue thing.

The problem with this though is, that this takes visible, interactive GUI components that fire that event.
What I’d like, however, is some sort of component that would spawn JOptionPane.showInputDialog just like a clicked button or context menu would, but without having to be interacted with by the user, but instead by the code.
I guess I could use invisible buttons and emulate mouseclick events, but that’s pretty hacky…

Also, I tried spawning Threads and Runnables which spawned the JOptionPane.showInputDialog, but that didn’t help either.
Unless I spawn the JOptionPane from a GUI source, everything stalls, and the dialog won’t work.

  • 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-28T14:20:30+00:00Added an answer on May 28, 2026 at 2:20 pm

    It should be possible for your background thread to spawn a dialog with invokeAndWait():

    final double[] result = new double[1];
    SwingUtilities.invokeAndWait(new Runnable() {
       public void run() {
          try {
             result[0] = Double.parseDouble(
                JOptionPane.showInputDialog("Enter value:"));
          } catch(NumberFormatException e) { 
             result[0] = -1;
          }
       }
    }
    // ... do something with result[0]
    

    Here I made the result an array just so that it can be final (accessible to the anonymous class) and also mutable.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but

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.