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

drawing lines between the java swing components in an applet

 
paskal sanil
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
I am confronted with a problem of drawing line between 2 JButtons in an applet. Could anyone help me as to how to do this !! I am using GridBagLayout to lay JButtons on the container.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest way to do this would be to override paintComponent( Graphics g ) on the JPanel (or other container) you are adding the buttons to, and draw the line using the g.drawLine( x1, y1, x2, y2 ) method. You should calculate the value of x1 and y1 from the location of one button, and x2 and y2 from the location of the other button.
 
Hot dog! An advertiser loves us THIS much:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!