0

Im trying to get some antialiasing on some JButtons Icons. How do I approach this? Right now Im intializing some icons and putting them with a selfmade repaint methode re() on my JButtons:

private void initializeIcons() {
        blackStone = new ImageIcon("src/assets/black.png");
        blackStone.setImage(blackStone.getImage().getScaledInstance(70, 70, Image.SCALE_DEFAULT));

        whiteStone = new ImageIcon("src/assets/white.png");
        whiteStone.setImage(whiteStone.getImage().getScaledInstance(70, 70, Image.SCALE_DEFAULT));

        blackDame = new ImageIcon("src/assets/black_dame.png");
        blackDame.setImage(blackDame.getImage().getScaledInstance(70, 70, Image.SCALE_DEFAULT));

        whiteDame = new ImageIcon("src/assets/white_dame.png");
        whiteDame.setImage(whiteDame.getImage().getScaledInstance(70, 70, Image.SCALE_DEFAULT));
    }


private void re() {
        for (int i = 0; i <= 7; i++) {
            for (int j = 0; j <= 7; j++) {
                if (fieldbutton[i][j].hasStone()) {
                    if (fieldbutton[i][j].getStone().isBlack() && !fieldbutton[i][j].getStone().isDame()) {
                        fieldbutton[i][j].setIcon(blackStone);
                    } else if (fieldbutton[i][j].getStone().isBlack() && fieldbutton[i][j].getStone().isDame()) {
                        fieldbutton[i][j].setIcon(blackDame);
                    } else if (!fieldbutton[i][j].getStone().isBlack() && fieldbutton[i][j].getStone().isDame()) {
                        fieldbutton[i][j].setIcon(whiteDame);
                    } else if (!fieldbutton[i][j].getStone().isBlack() && !fieldbutton[i][j].getStone().isDame()) {
                        fieldbutton[i][j].setIcon(whiteStone);
                    }
                } else
                    fieldbutton[i][j].setIcon(null);
            }
        }
}

Thanks in advance!

  • 1
    Why you need antialiasing? When your images are smaller than you need, so upscaling of images is often bad idea (and antialiasing in this case has no effect). Downscaling works usually better. For more information please provide a [mcve] so we can also see what's wrong in your code. Please also post the image which demonstrates, how looks now your apllication. – Sergiy Medvynskyy May 07 '18 at 15:56
  • 1
    BTW: have you tried to use another scaling constant? For example `Image.SCALE_SMOOTH`? – Sergiy Medvynskyy May 07 '18 at 15:58
  • So im the original size of the pictures is larger than I need them in my application. At original size everything looks fine but downscaled it looks aliased. `Image.SCALE_SMOOTH` helped!! Thanks a lot! – Fabian Zbinden May 07 '18 at 22:57

0 Answers0