• 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:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

drawing line in JFrame  RSS feed

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Bras cause cancer. And tiny ads:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!