6 Replies - 1109 Views - Last Post: 16 November 2012 - 04:53 AM Rate Topic: -----

#1 Tree55Topz  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 84
  • Joined: 06-September 12

adding png image to JPanel

Posted 15 November 2012 - 05:12 PM

Hello! What would be the best way to place a .png image on a JPanel? for instance if the picture was called flower.png, how should I go about importing it and making it visible on a JPanel? I tried messing around with BufferedImage but could not exactly get it. Also, would it work if the image was saved to my desktop? or would I have to put the image in a file and then into my workspace. Thank you!
Is This A Good Question/Topic? 0
  • +

Replies To: adding png image to JPanel

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: adding png image to JPanel

Posted 15 November 2012 - 05:14 PM

Before replying to that post...
I have already answer a lot of your posts
Do you reply sometimes "Thank you" ?
Or do you click +1

It is kind of frustrating to provide you with answer and not having a feed back if our answers were right/useful and fix the problem

Or you are part of the generation who just ask and don't give a shit of the person who spent time answering your post ?
Was This Post Helpful? 0
  • +
  • -

#3 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2643
  • View blog
  • Posts: 11,159
  • Joined: 20-September 08

Re: adding png image to JPanel

Posted 15 November 2012 - 05:16 PM

add(new JLabel(new ImageIcon("foo.png"));

Was This Post Helpful? 2
  • +
  • -

#4 Tree55Topz  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 84
  • Joined: 06-September 12

Re: adding png image to JPanel

Posted 15 November 2012 - 06:04 PM

Yes, you have answered several of my posts and almost all of them have been what I was looking for. I am new to dreamincode, I do not know exactly know what +1 means but I will definatly upvote your posts that help if that is what you mean. I have been in a programming fog all day, I am not trying to be rude. But please dont be so brash, I am not that type of person and I dont appreciate being thought of as so. Thank you for all of your help, you are truly a talented programmer.
Was This Post Helpful? 0
  • +
  • -

#5 Tree55Topz  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 84
  • Joined: 06-September 12

Re: adding png image to JPanel

Posted 15 November 2012 - 07:26 PM

g00se, I tried that
add(new JLabel(new ImageIcon("Warlock.png")), BorderLayout.CENTER);

Didnt quite work :/ I will show you the full code segment
class Instructions extends JFrame {
	private static JLabel instructions;
	private static JLabel p;
	Instructions(){
		instructions = new JLabel();
		add(new JLabel(new ImageIcon("Warlock.png")), BorderLayout.CENTER);
		instructions.setText("<html>YOU are the Arcane Inventor... A magical source that is responsible" +
							"<p> for creating all of the life-forms in existence. It is the Arcane " +
						     "<p>Inventor's job to combine elements of MIGHT, SOUL, and WISDOM to bring " +
							"<p>These beings into existence. Good Luck...</html>");
		instructions.setFont(new Font("Narkisim", Font.BOLD, 20));
		setLayout(new BorderLayout());
		setLocationRelativeTo(null);
		add(instructions, BorderLayout.SOUTH);
		
		
		
				
				
				
	}


}

Thanks for the help!
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10364
  • View blog
  • Posts: 38,390
  • Joined: 27-December 08

Re: adding png image to JPanel

Posted 15 November 2012 - 08:20 PM

Where is Warlock.png located?
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: adding png image to JPanel

Posted 16 November 2012 - 04:53 AM

Why do you mean "didn't quite work" ?
Do you see an Image at all ? If you see it, is it crooked, badly positionned, ?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1