• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

jpanel paint image using method like jpanel1.paint  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello guys there are many source code to paint image in jpanel but this time im trying to do this code like for example
i have a JPanel jpanel1 = new JPanel();
and i want to paint method link this code

"jpanel1.paint"

here is my code.



"Graphics graphics = " is my big problem how to draw image using this code? thanks in advance.
 
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's only one correct way.
http://download.oracle.com/javase/tutorial/uiswing/painting/index.html

If all you want to do is to display an image, the better way to do that is with JLabel and ImageIcon.
 
Jhovarie Guiang
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if using a jlabel and icon still there is a problem the image doest not fit into jlabel. and still we must use something like



or other to fit the image into jlabel.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

the image doest not fit into jlabel



It will, if you use a layout manager correctly.
http://download.oracle.com/javase/tutorial/uiswing/layout/index.html

Unless of course, you want the image to be scaled to a certain size, which could be one interpretation of your rather vague post. IMO that's better achieved by extending ImageIcon than by custom painting.

Why don't you go through the entire Swing tutorial trail? Programming is so much more fun when you understand what you're doing.
 
Jhovarie Guiang
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry but how does layoutmanager help to fit the image? is that by setting the layout of jlabel?

see my code but it does not work


and i also try to do like this

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!