Saturday, 30 June 2012

Calculate effective size of the window(excluding taskbar) in Java


Yesterday, I was working with generating a graph using jfreechart library. The requirement was to show a window with graph on full screen. When i used the following code it didn't give me the desired results. Taskbar was overlapping bottom part of the screen.

this.setPreferredSize(new Dimension(Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height));

After searching over internet i found the solution and following code snippet worked properly as per my requirements.

//Calculate height of the task bar
Insets scnMax = Toolkit.getDefaultToolkit().getScreenInsets(getGraphicsConfiguration());
int taskBarSize = scnMax.bottom;

this.setPreferredSize(new Dimension(Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height-taskBarSize));


Thanks!!!!!!!!!!!! Enjoy Programming :) 


No comments:

Post a Comment

Thanks for your valuable comments.

Gmail: Download blocked file

Hi, today we are going to learn, how to download blocked file in gmail. Sometimes you see following message in gmail: and you can...