File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Windows opened from menu items move down and to the right Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Windows opened from menu items move down and to the right" Watch "Windows opened from menu items move down and to the right" New topic
Author

Windows opened from menu items move down and to the right

Srikanth Adapa
Ranch Hand

Joined: Aug 21, 2008
Posts: 56
Hi all,

I ve a swing application which is having multiple modules(panels) and each module can be opened from every other module, as some menu items in the form of icons. But when I am trying to open and close any module multiple times, the window is moving down and to the right, so that the window buttons like minimum, restore, close are going outside the screen. Please let me know what modification can be done in order to view the complete window even on closing and opening multiple times.


Thank you in advance,

Sri.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

Is this a JDesktop / JInternalFrame solution, or using multiple dialogs / frames?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Srikanth Adapa
Ranch Hand

Joined: Aug 21, 2008
Posts: 56
All the individual modules are written using / extending JFrames internally.



Thanks,
Sri.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> But when I am trying to open and close any module multiple times, the
> window is moving down and to the right, so that the window buttons like
> minimum, restore, close are going outside the screen.

sounds like you are using setLocationRelativeTo(...), but adding the line
PRIOR to giving the frame a size (setSize or pack), so its positioning
is based on a size of (0,0) i.e. positions its top-left corner in the middle
of the relativeTo(...), which makes subsequent frame/s show "down and to the right"
Srikanth Adapa
Ranch Hand

Joined: Aug 21, 2008
Posts: 56
Dear Machael,

Can you please explain me a bit clear?


Thank you in advance,
Sri
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if you have your code this way

frame.setLocationRelativeTo(...);
frame.setSize(... , ...);//or frame.pack()

it should be the other way around

frame.setSize(... , ...);//or frame.pack()
frame.setLocationRelativeTo(...);
Srikanth Adapa
Ranch Hand

Joined: Aug 21, 2008
Posts: 56
I ve a common frame from which all other frames are being extended. I found that the window size is set as: initFrame(new Dimension(1020, 720));





Thanks,
Sri
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> I ve a common frame from which all other frames are being extended.
> I found that the window size is set as: initFrame(new Dimension(1020, 720));

how about you post the rest of the code of your 'common frame',
but just the bits relating to the frame - no components, listeners, menus etc
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Windows opened from menu items move down and to the right