Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   newbie JFileChooser question (http://www.velocityreviews.com/forums/t566129-newbie-jfilechooser-question.html)

Larry.Martell@gmail.com 01-03-2008 12:16 AM

newbie JFileChooser question
 
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

Brandon McCombs 01-03-2008 01:28 AM

Re: newbie JFileChooser question
 
Larry.Martell@gmail.com 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.

Larry.Martell@gmail.com 01-03-2008 03:57 PM

Re: newbie JFileChooser question
 
On Jan 2, 6:28 pm, Brandon McCombs <n...@none.com> wrote:
> Larry.Mart...@gmail.com 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

Lew 01-03-2008 04:02 PM

Re: newbie JFileChooser question
 
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.


Larry.Martell@gmail.com 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

Larry.Martell@gmail.com 01-04-2008 09:16 PM

Re: newbie JFileChooser question
 
On Jan 3, 9:02 am, Lew <l...@lewscanon.com> 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.

> Larry.Mart...@gmail.com 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

Lew 01-05-2008 12:35 AM

Re: newbie JFileChooser question
 
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?


Larry.Martell@gmail.com 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


All times are GMT. The time now is 05:52 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.