Friday, August 19, 2011

Making JButton Draggable

Hello Fellaws,


Today in this post we will try to add a feature in JButtons which will make them draggable in  any container i.e. JPanel,JFrame,JDialog etc.


Below is the download link of the API that will help you to add this feature in your project/code.
Download Here


Lets begin the procedure to add this feature in your code


Let us Start



  • Import this JAR file in your project. I am using NetBeans to develop my demo code. Steps are provided to import API in your code using NetBeans
    • Right click on your project name present on left Pane of Netbeans (Under which you have your .java files etc.
    • Select Properties, in the Project Properties Frame select Libraries on left pane
    • Click on Add Jar/Folder and select the above JAR file
    • You are done with importing API in your project




  • Now comes the code part, I am providing you the code below. Let me give you some details about the code.
    • The code contains JFrame which contains 2 JButtons
    • Now, MouseMotionListener is added in the JButtons passing an object of RavDragHandler class.
    • This will make your JButton Draggable :)




  • Congrats you have just added the Draggable JButton in your project :) 

Thats it for this Post.


Take Care


Peace



For Any Query mail me: ravjot.singh.28@gmail.com

No comments:

Post a Comment