Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

urgent! make a JPanel behave like a line  RSS feed

 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know this is wierd but I have to make a JPanel behave like a line, like for example I have a JPanel which looks like a link( a line ) between 2 icons, now I need to add popups to it ( thats y I cant use plain Graphics's line ) as well as stretch it like we could do to lines ( rubber banding )..any ideas?
making the panel look like a line is nothing new but rubberbanding the panels?
Thnx,
VV
 
Josh Rehman
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should urgently use Graphics/2D and use a mouseListener to detect if the mouse actually clicks on your lines. I fail to see how you can get a rectangular panel to go diagonally, anyway.
Swing has a ton of examples of doing these sorts of calculations, and there are tons of utility methods for doing this stuff in SwingUtilities.
 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Josh,
could u pls tell me how du add a listener to the Graphics2D object like a line, du have some sample code or something, the API's dont seem to support listeners.
The line needs to have properties viewed on popups so thats y a generic control is to be designed.
Vinod
 
Josh Rehman
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't add a listener to a line. but what you can do is draw a line in a panel, detect mouse clicks in that panel, and do something if that click occurs over the line. In this way it appears to the user that they are clicking on the line.
 
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!