newbie JFileChooser question

Discussion in 'Java' started by Larry.Martell@gmail.com, Jan 3, 2008.

  1. Guest

    I want to display a JFileChooser that is centered over the parent
    window.
    When I pass in the parent to showOpenDialog the file chooser is
    displayed
    centered on where the parent window was initially displayed. That is,
    if the
    parent window was moved to a new location, then the file chooser is
    NOT
    centered on the new location. It's as if the initial location of the
    parent window
    is remembered and not updated if the window is moved. How can I get
    the
    file chooser dialog to come up centered on its parent's current
    location?

    TIA!
    -larry
     
    , Jan 3, 2008
    #1
    1. Advertising

  2. wrote:
    > I want to display a JFileChooser that is centered over the parent
    > window.
    > When I pass in the parent to showOpenDialog the file chooser is
    > displayed
    > centered on where the parent window was initially displayed. That is,
    > if the
    > parent window was moved to a new location, then the file chooser is
    > NOT
    > centered on the new location. It's as if the initial location of the
    > parent window
    > is remembered and not updated if the window is moved. How can I get
    > the
    > file chooser dialog to come up centered on its parent's current
    > location?
    >
    > TIA!
    > -larry


    In the code before you display the dialog, get the current location for
    the parent window and pass those values as arguments into the
    setLocation() method for the dialog itself. That should fix your problem.
     
    Brandon McCombs, Jan 3, 2008
    #2
    1. Advertising

  3. Guest

    On Jan 2, 6:28 pm, Brandon McCombs <> wrote:
    > wrote:
    > > I want to display a JFileChooser that is centered over the parent
    > > window.
    > > When I pass in the parent to showOpenDialog the file chooser is
    > > displayed
    > > centered on where the parent window was initially displayed. That is,
    > > if the
    > > parent window was moved to a new location, then the file chooser is
    > > NOT
    > > centered on the new location. It's as if the initial location of the
    > > parent window
    > > is remembered and not updated if the window is moved. How can I get
    > > the
    > > file chooser dialog to come up centered on its parent's current
    > > location?

    >
    > > TIA!
    > > -larry

    >
    > In the code before you display the dialog, get the current location for
    > the parent window and pass those values as arguments into the
    > setLocation() method for the dialog itself. That should fix your problem.


    Thanks. This works when run on Mac and Windows, but it has no effect
    when the program
    is run on a Linux box and displayed back on a Windows box running
    cygwin.

    -larry
     
    , Jan 3, 2008
    #3
  4. Lew Guest

    Brandon McCombs wrote:
    >> In the code before you display the dialog, get the current location for
    >> the parent window and pass those values as arguments into the
    >> setLocation() method for the dialog itself. That should fix your problem.


    wrote:
    > Thanks. This works when run on Mac and Windows, but it has no effect
    > when the program
    > is run on a Linux box and displayed back on a Windows box running
    > cygwin.


    Is that using the usual Cygwin 'xwin' with the 'multiwindow' option?

    How are you connecting to the Linux box? If with ssh, are you port-forwarding
    the X session (-X or -Y option to ssh), or using a DISPLAY with the IP address
    of the windows box?

    If you log directly into the Linux box, does the technique work then?

    --
    Lew
     
    Lew, Jan 3, 2008
    #4
  5. Guest

    On Jan 3, 9:02 am, Lew <> wrote:
    > Brandon McCombs wrote:
    > >> In the code before you display the dialog, get the current location for
    > >> the parent window and pass those values as arguments into the
    > >> setLocation() method for the dialog itself. That should fix your problem.

    > wrote:
    > > Thanks. This works when run on Mac and Windows, but it has no effect
    > > when the program
    > > is run on a Linux box and displayed back on a Windows box running
    > > cygwin.

    >
    > Is that using the usual Cygwin 'xwin' with the 'multiwindow' option?


    Yes.

    > How are you connecting to the Linux box? If with ssh,


    Yes.

    > are you port-forwarding
    > the X session (-X or -Y option to ssh), or using a DISPLAY with the IP address
    > of the windows box?


    I don't invoke ssh with the -X or -Y option, but I don't explicitly
    set DISPLAY
    either. I just ssh in, and it works. If I look at $DISPLAY it's set to
    something
    like "localhost:11.0"

    > If you log directly into the Linux box, does the technique work then?


    I don't know - my only access to the linux box is via ssh from my
    Windows box.

    -larry
     
    , Jan 4, 2008
    #5
  6. Lew Guest

    Lew wrote:
    >> are you port-forwarding
    >> the X session (-X or -Y option to ssh), or using a DISPLAY with the IP address
    >> of the windows box?


    wrote:
    > I don't invoke ssh with the -X or -Y option,


    It must be set in your ssh_config then.

    > but I don't explicitly set DISPLAY either.
    > I just ssh in, and it works. If I look at $DISPLAY it's set to
    > something like "localhost:11.0"


    This value shows us that it is a port-forwarded DISPLAY, so the X events are
    traveling through the tunnel. Non-port-forwarded would be a non-localhost
    address.

    >> If you log directly into the Linux box, does the technique work then?


    > I don't know - my only access to the linux box is via ssh from my
    > Windows box.


    I can think of no reason why the technique should fail in your scenario. Too
    bad we can't see what happens natively on the Linux box.

    Can you debug, e.g., run the program through your IDE, and see what values are
    come in when you
    >> get the current location for the parent window

    in order to
    >> pass those values as arguments into the setLocation() method for the dialog itself

    (Brandon McCombs)?

    This would narrow the behavior down to whether you're getting wrong
    coordinates or failing to set correct ones.

    --
    Lew
     
    Lew, Jan 5, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roedy Green
    Replies:
    0
    Views:
    741
    Roedy Green
    Jul 9, 2003
  2. alexonjava99
    Replies:
    0
    Views:
    1,762
    alexonjava99
    Jul 26, 2003
  3. Mr. Deckard

    Re: JFileChooser & RMI

    Mr. Deckard, Aug 10, 2003, in forum: Java
    Replies:
    2
    Views:
    1,386
    Stephen Gilbert
    Aug 10, 2003
  4. Kay

    JFileChooser?

    Kay, Aug 18, 2003, in forum: Java
    Replies:
    2
    Views:
    662
  5. dota
    Replies:
    8
    Views:
    14,059
    Andrew Thompson
    Feb 18, 2004
Loading...

Share This Page