Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder brad211987's Avatar
    Join Date
    Sep 2005
    Location
    Ohio
    Posts
    631
    Thanks
    10
    Thanked 50 Times in 50 Posts

    (Java) inputDialog problem

    When I use JOptionPane.showInputDialog() the input dialog pops up behind any other windows on the screen at the time. Anyone know how to fix that? Not a huge problem but its irritating.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    It should automatically focus itself. Can you post your code please?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder brad211987's Avatar
    Join Date
    Sep 2005
    Location
    Ohio
    Posts
    631
    Thanks
    10
    Thanked 50 Times in 50 Posts
    Code:
            String list[] = {"100","400","900","1600"};
            String value = null;
    
            while(value == null)
            {
                value = (String)JOptionPane.showInputDialog(null,"How many cells do you want?",
                    "John Conway's Game Of Life",JOptionPane.INFORMATION_MESSAGE,null,list,list[1]);
                    
                if (value == null)
                    JOptionPane.showMessageDialog(null,"You must choose a number.",
                        "ERROR",JOptionPane.ERROR_MESSAGE);
            }
    This is the section of code that the input dialog is in. Do you think that it could possibly have something to do with the IDE? I had this problem when programming in highschool as well.

  • #4
    Regular Coder brad211987's Avatar
    Join Date
    Sep 2005
    Location
    Ohio
    Posts
    631
    Thanks
    10
    Thanked 50 Times in 50 Posts
    I downloaded another IDE and ran it with that and sure enough, the dialog pops up right in front.

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Hmm why are you type casting the inputDialog box? The input given is a string by default. No need to type cast it.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    Regular Coder brad211987's Avatar
    Join Date
    Sep 2005
    Location
    Ohio
    Posts
    631
    Thanks
    10
    Thanked 50 Times in 50 Posts
    When I don't cast the inputdialog i get:

    incompatible types - found java.lang.Object but expected java.lang.String


    Still trying to figure that one out because I have never seen a showInputDialog() method that returns an object. Type casting is a remedy for now but still looking for why it needs it. Maybe it has something to do with using a list in the dialog.

  • #7
    Regular Coder brad211987's Avatar
    Join Date
    Sep 2005
    Location
    Ohio
    Posts
    631
    Thanks
    10
    Thanked 50 Times in 50 Posts
    Code:
    static Object 	showInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue)
    I was wrong, I finally got the docs to load up on this slow college net and found that it does in fact return an object. Thanks for reminding me to look that one up though, I had forgotten about that issue and now I get it.

  • #8
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I need to create an InputDialog using JOptionPane with two input fields an a large information message. How can I do this? Or may be it's better to create a JDialog?

  • #9
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Sounds like you will be using a JFrame or JPanel. Have you worked with either of these yet? The input won't be hard once you get the actual window working.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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