Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

drawing line in JFrame

 
Nirmal JeyaChandra
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
 
Michael Dunn
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?
 
Jeff Albertson
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 ]
 
Gregg Bolinger
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
 
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!