How to fit an image in a window so that the taskbar does not cover it over.

Hey all,

 So I've bumped into some issues with putting a background in a program I've been working on recently. The program uses relative positioning in Swing to lay out all of the gui components and creates different scaled images for the background based on the window size which is in turn based on the screen size.

 The JFrame takes up the whole screen, and while I could shrink the window so that the taskbar didn't lay on top of it, how I can tell how big the taskbar is, how I can tell where it's located on different computers, ect are real problems.

 Is there any way I could track the size and location of the taskbar and adjust the image accordingly? 

Current background code:


//Outside of constructor:
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
double width = screenSize.getWidth();
double height = screenSize.getHeight();
int intHeight = (int)height;
int intWidth = (int)width;	




//set the size of the JFrame, order matters
	this.setSize(intWidth, intHeight);


	Dimension screenSize = this.getBounds().getSize();
	 width = screenSize.getWidth();
	 height = screenSize.getHeight();
	int intHeight = (int)height;
	int intWidth = (int)width;
	
	
	//Create the icon for the background label
	//note, I took some forum advice here and I'm not 100% clear on what the graphics class does
	try{
	final ImageIcon wp = new ImageIcon(getClass().getResource("/layouttest.png"));	
	  Image wallPaper = wp.getImage();
	 
	  //This code section brought by the recommendations of stack overflow and slightly modified
	  Image scaledImage = wallPaper.getScaledInstance((int)width, (int)height, Image.SCALE_FAST);
      BufferedImage backgroundBuff = new BufferedImage((int)width, (int)height, BufferedImage.TYPE_INT_RGB);
      Graphics g = backgroundBuff.createGraphics();
      g.drawImage(scaledImage, 0, 0, new Color(0,0,0), null);
      g.dispose();
	

	ImageIcon newIcon = new ImageIcon(scaledImage);
	JLabel background =  new JLabel(newIcon);
	contentPane.add(background, new Integer(0));
	size = background.getSize();
	background.setBounds(0, 0, intWidth, intHeight - 50);
	backgroundSize = background.getSize();
	}
	catch (Exception e)
	{
		System.out.println("Error, file not found");
	}
	

Any help at all would be very much appreciated.

I don’t think most of the popular operating systems have taskbars that cover the active window… You really shouldn’t force full screen like that anyway, it’s annoying. Either literally make the game full screen (IE no window decorations since you’re using Swing) or have it be a reasonable size but not taking up the entire screen.

I admit I am testing the game on a Windows 7 computer which is about 4 years old (the computer, that is).

The problem with avoiding full screen is that I’m trying to deal with the issue of multiple resolutions. I’ve sort of been setting up equations to the effect of “Put this thing half way across the screen” in order to deal with the shifting that occurs when the aspect ratio changes. I suppose I could adjust those, but… ugh. Dealing with multiple resolutions gets really complex really fast.