File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JFrame" Watch "JFrame" New topic


remi vandana

Joined: Aug 24, 2001
Posts: 6
pl. help me in acheving foll...
i hv JMenu attached to JFrame.
i hv a JDialog boxes wch are invoked by clicking on JmenuItems.
the prob is tht, i hv a 17 inch monitor and i hv used setLocation() method to place thd dlg box on JFrame. Whenever the dialog box appears its at the location wch i hv set but if the same code is run on 14 inch or 15 inch or on any other dimennsion of monitor the location on tht monitor is unpredictable....
either the dlg box is shifted to some corner or it almost gets hidden...
how to set correct locaton of dlg so tht its appearance remins same on all kinds of monitors of any dim. also i want tht all the dlg boxes of any size shd appear exactly in middle of the JFrame.
i also used getDefaultToolkit method.
pl. reply soon....
Vinod Venugopal
Ranch Hand

Joined: Dec 06, 2000
Posts: 148
Well, actually speaking getToolkit should do, would like to c ur code, but anyway heres some sample code u can use...
// centers the dialog within the screen
public void centerScreen()
Dimension dim = getToolkit().getScreenSize();
Rectangle abounds = getBounds();
setLocation((dim.width - abounds.width) / 2,
(dim.height - abounds.height) / 2);

- Vinod<br />-------<br />SCJP2
I agree. Here's the link:
subject: JFrame
jQuery in Action, 3rd edition