package com.dreikraft.swing; import java.awt.Graphics; import java.awt.Image; /** * BackgroundDesktopPane * @author jan.illetschko@3kraft.com */ public class BackgroundDesktopPane extends javax.swing.JDesktopPane { private boolean scale; private Image backgroundImage = null; /** * Creates new form BeanForm */ public BackgroundDesktopPane() { initComponents(); } @Override public void paint(Graphics g) { super.paint(g); if (getBackgroundImage() != null) { if (isScale()) { g.drawImage(getBackgroundImage(), 0, 0, getWidth(), getHeight(), this); } else { int width = getBackgroundImage().getWidth(this); int height = getBackgroundImage().getHeight(this); int xStart = (int) (((double) (getWidth() - width)) / 2.0); int yStart = (int) (((double) (getHeight() - height)) / 2.0); g.drawImage(getBackgroundImage(), xStart, yStart, width, height, this); } paintChildren(g); } } public boolean isScale() { return scale; } public void setScale(boolean scale) { this.scale = scale; } public Image getBackgroundImage() { return backgroundImage; } public void setBackgroundImage(Image backgroundImage) { this.backgroundImage = backgroundImage; this.repaint(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents private void initComponents() { setBackground(new java.awt.Color(255, 255, 255)); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables }