ButtenImage not working well

why when i use this code, my whole ui is covered with the button? What is weird, is that the image has the size 100 x 100 but the button just covers the whole ui
try {

BufferedImage img = ImageIO.read(new File("src/goldbarren.png"));

Image scaledImg = img.getScaledInstance(100, 100, Image.SCALE_SMOOTH);
ImageIcon icon = new ImageIcon(scaledImg);


JButton klickButton = new JButton(icon);
klickButton.setBounds(100, 100, 100, 100);


klickButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
punkte += punkteProKlick;
punkteLabel.setText("Punkte: " + punkte);
}
});
try {

BufferedImage img = ImageIO.read(new File("src/goldbarren.png"));

Image scaledImg = img.getScaledInstance(100, 100, Image.SCALE_SMOOTH);
ImageIcon icon = new ImageIcon(scaledImg);


JButton klickButton = new JButton(icon);
klickButton.setBounds(100, 100, 100, 100);


klickButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
punkte += punkteProKlick;
punkteLabel.setText("Punkte: " + punkte);
}
});
1 Reply
JavaBot
JavaBot2mo ago
This post has been reserved for your question.
Hey @denk! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here. 💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server