newbie JFileChooser question

L

Larry.Martell

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
 
B

Brandon McCombs

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.
 
L

Larry.Martell

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
 
L

Lew

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?
 
L

Larry.Martell

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
 
L

Lew

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.
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(Brandon McCombs)?

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top