Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Keyevent while JOptionPane inputdialog is open

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Keyevent while JOptionPane inputdialog is open

    Is there a way to do a keyevent while a joptionpane.inputdialog is open?
    I dont want a keyevent to happen before a inputdialog is open or after, I want a keyevent to happen exactly while the inputdialog is open


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Keyevent while JOptionPane inputdialog is open

    Can you make a small, complete program that compiles, executes and shows the problem.

    I don't know what events can happen when a modal dialog is open.

    If you want a non-modal window, use the JDialog class.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Keyevent while JOptionPane inputdialog is open

    import java.awt.AWTException;
    import java.awt.Robot;
    import java.awt.event.KeyEvent;

    import javax.swing.JOptionPane;

    public class key {
    public static void main(String[]args) throws AWTException{
    final Robot robot = new Robot();

    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_X);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.keyRelease(KeyEvent.VK_X);

    String area = JOptionPane.showInputDialog("");

    }
    }
    Here does the keyevent happened before the input dialog shows, I want the keyevent to happen when the input dialog is open.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Keyevent while JOptionPane inputdialog is open

    You will need to use threads if you want the Robot methods to happen when the JOption pane is open. Not sure what the timing requirement will be to get the event to happen after the dialog is shown.

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. JOptionPane Problem
    By shen_punkz21 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 24th, 2013, 11:22 AM
  2. Replies: 1
    Last Post: August 3rd, 2012, 11:46 AM
  3. Using Keyevent
    By sbjibo in forum AWT / Java Swing
    Replies: 1
    Last Post: June 2nd, 2012, 12:14 PM
  4. KeyEvent Running Twice?
    By JuLiAnc in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2012, 04:43 PM
  5. JOptionPane using If and Else
    By Liuric in forum Member Introductions
    Replies: 7
    Last Post: October 1st, 2010, 12:05 AM

Tags for this Thread