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 :)
Take Care
Peace
For Any Query mail me: ravjot.singh.28@gmail.com
thanks a lot!
ReplyDeleteworks perfectly
Excellent Work!
ReplyDeleteIt helps me alot.
Thanks!