hi, 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
posted
0
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); super.setVisible(true); //requestFocus(); }