Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JFrame

 
remi vandana
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic