Example #1
0
 private static ImageIcon makeRolloverIcon(ImageIcon srcIcon) {
   RescaleOp op =
       new RescaleOp(new float[] {1.2f, 1.2f, 1.2f, 1f}, new float[] {0f, 0f, 0f, 0f}, null);
   BufferedImage img =
       new BufferedImage(
           srcIcon.getIconWidth(), srcIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics g = img.getGraphics();
   // g.drawImage(srcIcon.getImage(), 0, 0, null);
   srcIcon.paintIcon(null, g, 0, 0);
   g.dispose();
   return new ImageIcon(op.filter(img, null));
 }
Example #2
0
  private JLabel makeLabelIcon() {
    ImageIcon i = new ImageIcon(getClass().getResource("duke.gif"));
    Dimension d = new Dimension(i.getIconWidth(), i.getIconHeight());
    final BufferedImage image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB);
    Graphics g = image.createGraphics();
    i.paintIcon(null, g, 0, 0);
    g.dispose();
    final JLabel icon =
        new JLabel(i) {
          @Override
          public boolean contains(int x, int y) {
            return super.contains(x, y) && ((image.getRGB(x, y) >> 24) & 0xff) != 0;
          }
        };
    icon.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
    MouseAdapter l =
        new MouseAdapter() {
          private final transient Point start = new Point();
          private Point loc;

          @Override
          public void mousePressed(MouseEvent me) {
            start.setLocation(me.getPoint());
          }

          @Override
          public void mouseDragged(MouseEvent me) {
            loc = icon.getLocation(loc);
            int x = loc.x - start.x + me.getX();
            int y = loc.y - start.y + me.getY();
            icon.setLocation(x, y);
          }
        };
    icon.addMouseListener(l);
    icon.addMouseMotionListener(l);
    icon.setBounds(new Rectangle(22, 22, d.width, d.height));
    return icon;
  }