• Post Reply Bookmark Topic Watch Topic
  • New Topic

get window on viewable screen  RSS feed

 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing my GUI today, been at it for a day or two working off of previous work. I struggled earlier trying to get the constructor to place something reasonable on the screen. I got one code version to work, that was months ago. Here is what is probably useable from the earlier effort:

Probably the call to super.getSize() is in the wrong place and should be moved to refresh() / updateUI or something.

I want to center on the screen using a default range of 640/480 to 1024/768 - the user can resize if uncomfortable. All reviews welcome.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you just want to center the frame on the screen (at whatever resolution),
ensure the frame is sized:
frame.pack(); or
frame.setSize(w,h);
then
frame.setLocationRelativeTo(null);

note: the order must be
sized
location

other way around and it won't work
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is where I placed your advice temporarily in my code, I thought that sizing has to be passed useable parameters. First efforts resulted in miniature windows or that type of first effort result. The code other than the snippet from you is what I had before posting.

I have today to work on this.

{ message edit: I worked all day on this, tracers put in the code show ( Window width: 648.0 / Window height: 486.0 ) but the window shows up taking all the screen area. }
[ May 13, 2008: Message edited by: Nicholas Jordan ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!