• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

drawing line in JFrame

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.awt.Image image = jPanel1.getToolkit().getImage(imageFile);
java.awt.Graphics g = jPanel1.getGraphics();
//g.drawImage(image, 0, 0, jPanel1);


Is there any code similar to above code for drawing line when used in Jframe
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what happened when you looked up the available methods in the Graphics class?
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Dunn:
what happened when you looked up the available methods in the Graphics class?



Gotta love that Socratic Method: "and what would happen if you looked into your microscope?"
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More seriously, if you want to do some drawing the typical approach is to create your own component class by subclassing JComponent or JPanel, overriding paintComponent and doing your drawing there. Add this component to your GUI like any other component:If you haven't already, take a look at Sun's graphics tutorial:

http://java.sun.com/docs/books/tutorial/2d/index.html
[ January 09, 2006: Message edited by: Jeff Albrechtsen ]
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or if you are just looking for a separator type line use the JSeparator class.
 
Nirmal JeyaChandra
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used paintComponent() of JComponent as suggested by you. It is working fine thank you very much for it.

How to update the screen when using paintComponent() method. I tried repaint() and by calling paintComponent() directly it is not updating.

please help me.

Thanks in advance
 
reply
    Bookmark Topic Watch Topic
  • New Topic