I tried to put an image on a JButton and it's messed up:

http://imgur.com/ecBOt


code:

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;

public class Polluted extends JFrame implements ActionListener {
	ImageIcon bg = new ImageIcon("bg.png");
	Image bgImage = bg.getImage();
	public static void main(String[] args) {
	new Polluted();

	}
	
	public Polluted()
	{
		JPanel panel = new JPanel();
		Image playImage = getToolkit().createImage("play.png");
		ImageIcon playButton = new ImageIcon(playImage);
		this.setSize(800, 500);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setTitle("Polluted");
		this.setResizable(false);
		this.setLayout(new GridBagLayout());
		JButton play = new JButton(playButton);
		this.add(play);
		this.setVisible(true);
	
	}
	
	
	public void paint(Graphics g)
	{
		Graphics2D g2 = (Graphics2D)g;
		
		
		g2.setRenderingHint(
				RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
	
		Toolkit bgKit = Toolkit.getDefaultToolkit();
		bgImage = bgKit.getImage("bg.png");
		g.drawImage(bgImage, 0, 0, this);
		
	}
	
	
	
	
	public void actionPerformed(ActionEvent donotuse) {
	
		
	}

}

also if you could help me make a background image work that would be cool :3

Thanks in advance, upanotch

Can you explain what "messed up" means? What were we supposed to see in the posted image?

Can you explain what "messed up" means? What were we supposed to see in the posted image?

the Jbuttons edges are in there, it's not just a clickable image

it's not just a clickable image

What is supposed to happen when you click on the button?
You need to add an actionListener if you want the program to react.

What is supposed to happen when you click on the button?
You need to add an actionListener if you want the program to react.

I understand that, I mean that the button looks weird

Change the image to something that is not weird looking.

Can you show a non-weird image vs a weird image?

Edited 5 Years Ago by NormR1: n/a

Change the image to something that is not weird looking.

Can you show a non-weird image vs a weird image?

the image looks fine, I mean it doesn't look like the menu buttons in minecraft or something

This article has been dead for over six months. Start a new discussion instead.