Showing posts with label draggable. Show all posts
Showing posts with label draggable. Show all posts

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

Sunday, August 14, 2011

Making Undecorated JFrame or Without Title bar JFrame or Window draggable

Hello Fellaws,


Well we have developed many Java application with or without Title bar of JFrame.


Most of us use setUndecorated(true); for JFrame to make their application attractive.


Famous applications that use this type of styles are iTunes, Winamp etc.


But, the problem Java developer face is that we can not make our JFrame dragged which is an awful feature :(


To help you all I am providing you an API which you can import in your project and with 3 lines you can add this drag feature to your undecorated JFrames.


You can download the API from below link
Download Here


Let us begin with the steps



  • 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 well let me give you brief detail about the code. 
    • I have developed a CustomJPanel class which extends JPanel and adds few JLabels, JButton and JTextField etc. 
    • It is simple GUI and this JPanel is added in JFrame.
    • This API will provide you MouseListener and MouseMotionListener which should be added to JPanel or the JComponent you add on you JFrame (which is undecorated).
    • For your reference I am providing you the CustomJPanel Code Download Here
  • The code creating an undecorated JFrame and with CustomJPanel object is given below




  • Congrats you have developed an undecorated JFrame which can now drag :)
Thats it for this Post.


Take Care


Peace



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