Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Windows opened from menu items move down and to the right

 
Srikanth Adapa
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this a JDesktop / JInternalFrame solution, or using multiple dialogs / frames?
 
Srikanth Adapa
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the individual modules are written using / extending JFrames internally.



Thanks,
Sri.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Machael,

Can you please explain me a bit clear?


Thank you in advance,
Sri
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic