Graphics2D g2 = (Graphics2D)g;
int width = getSize().width;
int height = getSize().height;
// Explicitly clear the window.
Rectangle clear = new Rectangle(0, 0, width, height);
g2.setPaint(getBackground());
g2.fill(clear);
// Clip the first image, if appropriate,
// to be on the right side of the split.
if (mSplitX != 0 && mSecondImage != null) {
Rectangle firstClip = new Rectangle(mSplitX, 0,
width - mSplitX, height);
g2.setClip(firstClip);
}
g2.drawImage(getImage(), 0, 0, null);
if (mSplitX == 0 || mSecondImage == null) return;
Rectangle secondClip = new Rectangle(0, 0, mSplitX, height);
g2.setClip(secondClip);
g2.drawImage(mSecondImage, 0, 0, null);
Line2D splitLine = new Line2D.Float(mSplitX, 0, mSplitX, height);
g2.setClip(null);
g2.setColor(Color.white);
g2.draw(splitLine);