方法一:取屏幕大小(去掉任务栏的高度部分)     

Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
//上面这种方式获取的是整个显示屏幕的大小,包含了任务栏的高度。
Insets   screenInsets   =   Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());   
   Rectangle   desktopBounds   =   new   Rectangle(   
                    screenInsets.left,   screenInsets.top,     
                    screenSize.width   -   screenInsets.left   -   screenInsets.right,   
                    screenSize.height   -   screenInsets.top   -   screenInsets.bottom);

 


方法二: java(Swing)获取任务栏的高度


import java.awt.Insets;
import java.awt.Toolkit;

import javax.swing.JFrame;
public class TaskHeightTest extends JFrame{
	private static final long serialVersionUID = 6587866382008362321L;

	public static void main(String[] args) {
		TaskHeightTest t=new TaskHeightTest();
		//获取屏幕边界
		Insets   screenInsets   =   Toolkit.getDefaultToolkit().getScreenInsets(t.getGraphicsConfiguration()); 
		//取得底部边界高度,即任务栏高度
		int taskHeight=screenInsets.bottom;     
		     System.out.println(taskHeight);
	}

}

方法三:

GraphicsEnvironment graphicsEnvironment=GraphicsEnvironment.getLocalGraphicsEnvironment(); 
//get maximum window bounds
Rectangle maximumWindowBounds=graphicsEnvironment.getMaximumWindowBounds();
//这种方式能够获取除去任务栏的高度,在想定位到弹出消息框到右下角的是时候很有用处。