title: Darken JButton(s) on hover/click
body: <pre><code>ImageIcon backpackImageIcon = new ImageIcon("images/gui/button_backpack.png");
  JButton backpackButton = new JButton();
  backpackButton.setBounds(660,686,33,33);
  backpackButton.setBorderPainted(false);
  backpackButton.setFocusPainted(false);
  backpackButton.setVisible(true);
  backpackButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("B"), "backpackButtonPress");
  backpackButton.getActionMap().put("backpackButtonPress", ClassBackpackButton);
  backpackButton.setAction(ClassBackpackButton);
  backpackButton.setIcon(backpackImageIcon);
  backpackButton.setToolTipText("Backpack[B]");
  panel.add(backpackButton);      
  </code></pre>
  
  <p>I have multiple buttons set up this exact way.  What I was hoping to be able to do was to have them darken 10% on hover and maybe 20% on click.  I tried to look around for how to do this but had no luck(only found javascript stuff).  Sorry if this has been asked before and thanks for any help.</p>
  
  <p>** <strong><em>EDIT</em></strong> **</p>
  
  <p>I have tried to do this but it just turns the image blank:</p>
  
  <pre><code>BufferedImage bufferedImage = null;
  try {
      bufferedImage = ImageIO.read(new File("images/gui/button_backpack.png"));
  } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }
  BufferedImage darkerBackpackBufferedImage = new BufferedImage(32, 32, BufferedImage.TYPE_BYTE_INDEXED);
  RescaleOp op = new RescaleOp(1.3f, 0, null);
  darkerBackpackBufferedImage = op.filter(bufferedImage, null);
  ImageIcon darkerBackpackImageIcon = new ImageIcon((Image) darkerBackpackBufferedImage);
  backpackButton.setRolloverIcon((ImageIcon) darkerBackpackImageIcon);
  </code></pre>
  
  <p>** <strong><em>EDIT</em></strong> ** with solution</p>
  
  <p>here is the modified shiftColor function that I went with for anyone reading this above... good luck :)</p>
  
  <pre><code>public BufferedImage shiftColor(BufferedImage img, int rShift, int gShift, int bShift) {
      Color tmpCol;
      int tmpRed, tmpGreen, tmpBlue;
      for (int x = 0; x &lt; img.getWidth(); x++) {
          for (int y = 0; y &lt; img.getHeight(); y++) {
              tmpCol=new Color(img.getRGB(x,y));
              tmpRed = (tmpCol.getRed()-rShift &lt; 0) ? 0 : tmpCol.getRed()-rShift; //if shifted color is less than 0 change to 0
              tmpGreen = (tmpCol.getGreen()-gShift &lt; 0) ? 0 : tmpCol.getGreen()-gShift; //if shifted color is less than 0 change to 0
              tmpBlue = (tmpCol.getBlue()-bShift &lt; 0) ? 0 : tmpCol.getBlue()-bShift; //if shifted color is less than 0 change to 0
              tmpCol=new Color(tmpRed, tmpGreen, tmpBlue);
              img.setRGB(x,y,tmpCol.getRGB());
          }
      }
      return img;
  }
  </code></pre>