aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes about centering of the frame and using the new frame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "about centering of the frame and using the new frame" Watch "about centering of the frame and using the new frame" New topic
Author

about centering of the frame and using the new frame

Roldan Baldo
Ranch Hand

Joined: Aug 11, 2009
Posts: 99
first I set choices then if any of that choices been selected a new frame will appear, but my problem is i want to use the button of that new frame but i cant click. i know it is because i use do while in there but i put it there because when i close the new frame the choices will then appear until the user enter exit.

how to rearrange the code or is there something else i will add to my code.



and also how to make the new frame into center, because it always appear at the top left of the screen.
Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
If you want to do something on button click, you have to add actionListener to the button. You can find information in the related Java tutorial.
For centering the frame, you have to get the size of the screen, and then based on that you can position your frame. You can easily find a solution for this by a little search.
Roldan Baldo
Ranch Hand

Joined: Aug 11, 2009
Posts: 99
yes i know how to add an actionlistener to that button but i mean when i clik the frame, i cannot because theres a priority window which is my choices.

about the centering of the new frame i dont know how to search because i dont know the name of what i am going to search.
Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
First of all I can't believe what you say. Just try a simple google search with the keywords: java center frame
Second:
Now I checked the code, more carefully. Please always post real code. The line

is not a valid line.
One solution for you problem would be to change the ending condition of the while loop. The current condition has no meaning, since when choice equals 0 you quit the application.
So you should write something like:

P.S.:
Please always use meaningful subject line.
Here you can find the FAQ of question posting. I highly recommend to read it carefully.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
To put the frames in the middles of the screen, try their setBounds or similar methods.
JOptionPane dialogues are modal dialogues by default. As soon as you have got rid of the dialogue, another appears, and that blocks the thread.
And please always tell us what the thread is about
Roldan Baldo
Ranch Hand

Joined: Aug 11, 2009
Posts: 99
i apologize for the code and for the topic, i will edit it. and i now make it center, what i did is i made frame.setLocation(450,300) i dont know when i run this on other PC if it will be the same location, because i think it differs to the screen of the monitor.

my other problem is the do while which affects the new frame, and i cant use it.

Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
I answered both of your question Roldan, just read it;)
Your solution obviously won't work correctly on other computers, it won't even work on your computer whenever you change the screen resolution or you change the size of the frame.
Roldan Baldo
Ranch Hand

Joined: Aug 11, 2009
Posts: 99
im sorry for that, but it still didnt work, what i mean is

when i choose 1 or 2 or 3 except 0 a new frame will appear, and in the new frame i have something to work on, like buttons to click, etc, i have some codes to add, when i will close the frame, the choices will then appear, it is just like that.

the problem is i cant work on the new frame, like clicking a button, because the choices frame will bother the new frame.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

Campbell Ritchie wrote:To put the frames in the middles of the screen, try their setBounds or similar methods.

setLocationRelativeTo(null) is a better option. Let the API do the hard work


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Roldan Baldo
Ranch Hand

Joined: Aug 11, 2009
Posts: 99
thanks, i now centered it..

only the other problem is lacking..
Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
Now I understand your problem. Why don't you use modal JDialogs instead of JFrames? That would solve your problem.
Roldan Baldo
Ranch Hand

Joined: Aug 11, 2009
Posts: 99
yes, thanks a lot guys.. that solves the problem.
 
jQuery in Action, 2nd edition
 
subject: about centering of the frame and using the new frame