Having a frustrating time with a simple subclass of JPanel. I subclassed JPanel so that I could overwite the paint method for scaling purposes. Here' s paint
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
// Compute image scale so that largest dim fits panel.
float ih = image.getHeight(this);
float iw = image.getWidth(this);
float ar = ih/iw;
// Scale the larger dim to fit panel
float scale = 1.0f;
if (ar > 1) scale = this.getHeight()/ih;
else scale = this.getWidth()/iw;
g2d.scale(scale, scale);
g2d.drawImage(image,20,20,this);
}
The problem is no matter what I try, I get a gray background (parent frame background) and no border. I have set the background in several places, in the test driver when the panel is created and added to a JFrame, in the constructor, and even in the paint routine. Nothing seems to effect the display. The image shows up scaled, but that part of the panel that is not image is still gray. If, in the constructor, I call isBackgroundSet() and getBackground(), they return "true" and "WHITE", but the background still shows ggggrrrrraaaayyyyy!
Anybody know what's wrong?
Thanks Mike