954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

JButton image messed up?

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

upanotch
Newbie Poster
5 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

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

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 
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

upanotch
Newbie Poster
5 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 
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.

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 
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

upanotch
Newbie Poster
5 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

Change the image to something that is not weird looking.

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

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 
mKorbel
Veteran Poster
1,141 posts since Feb 2011
Reputation Points: 480
Solved Threads: 224
 

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

upanotch
Newbie Poster
5 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

Sorry, I have no idea what menu buttons look like in those programs.

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: