JFrame
i have JFrame of size(400,300) i want to diaplay this frame at the center fo screen, can you please help me out.??
thanks
Hiral
Web Development
i have JFrame of size(400,300) i want to diaplay this frame at the center fo screen, can you please help me out.??
thanks
Hiral
by okujava
here it is:
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int x = (screenSize.width - frame.getWidth())/2;
int y = (screenSize.height - frame.getHeight())/2;
frame.setLocation(x, y);
it is positioned in the center no matter what's the size of the frame.
by ahiral
by diva_cen2000
regards,
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension dframe=getSize();
int x = (screenSize.width - dframe.getWidth())/2;
int y = (screenSize.height - dframe.getHeight())/2;
frame.setLocation(x, y);
by diva_cen2000
sorry ,
add this line after first two lines
if(dframe.width>screenSize.width)
dframe.width=screenSize.width;
if(dframe.heigth>screenSize.heigth)
dframe.height=screenSize.height;
by ahiral
by ahiral
This discussion is closed to new replies.
Sort by Trending