Results 1 to 2 of 2
  1. #1
    darrell22 is offline Member
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Default How to Center JOptionPane within JFrame?

    Dear Experts,


    I have a java GUI app. It is the usual textpad assignment.
    JFrame, JTextArea, menus.

    Off the Search menu, I have a option to Find a string.
    Which opens a JOptionPane to get the input.


    The JOptionPane keeps coming up within the center of the screen.
    I'd like to center it within the JFrame.

    Interestingly, setLocation does change its location at all.

    I've been fighting and googling with this for hours,
    and I'm into my second day now.

    How can I center a JOptionPane within a JFrame?

    Thanks a lot!


    See code here:


    private class FindHandler implements ActionListener
    {

    @Override
    public void actionPerformed ( ActionEvent event )
    {


    jp = new JOptionPane();


    jp.setLocation(20, 300);
    jp.setVisible(true);


    stringToFind = jp.showInputDialog
    ("Enter the string to search for" );

    // etc



    }

  2. #2
    darrell22 is offline Member
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Default Re: How to Center JOptionPane within JFrame?

    Ok, I figured it out.

    You have to put the parent component as a parameter in showInputDialog.

    stringToFind = jp.showInputDialog
    ( ta, "Enter the string to search for" );

    Once I put a post here, it must have been scared of you all!

Similar Threads

  1. Return result from JOptionPane to JFrame
    By cselic in forum AWT / Swing
    Replies: 25
    Last Post: 05-15-2010, 08:40 AM
  2. JOptionPane to JFrame
    By mitty in forum New To Java
    Replies: 5
    Last Post: 04-12-2010, 04:57 PM
  3. JFrame at Center Screen
    By hiranya in forum AWT / Swing
    Replies: 8
    Last Post: 02-11-2010, 04:29 PM
  4. center a form
    By tommy in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 08:47 PM

Tags for this Thread

Posting Permissions

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