Reputation: 43
I am very new to Java Swing programming and I have a small problem.
When I design a user interface using Jframe and JPanels, JPanel does not allow to drag and drop an item in a place I desire (At design time ). Lets say I add a button to JPanel, then the button is stuck in the middle of the panel and I cannot drag it to a place I desire.This does not happen when I add items directly to the JFrame.
I tried using setBounds(int x, int y, int width, int height)
method to move the button in JPanel but it did not work.Following image would describe my problem well. I want to drag the button in the JPanel to the left, just like the button added in the JFrame.
Button in JPanel - Top and JFrame - Bottom:
Is there a way to drag and drop items freely in the JPanel as well?
Thanks.
Upvotes: 4
Views: 2256
Reputation: 21
Go to the properties of the Jframe or JPanel, there is a property as Layout, select the 'Abosolute Layout' from them. Then you can place any AWT Component you desire.
Upvotes: 1
Reputation: 212
Posting as an answer since I do not have enough reputation to comment. I see you are using eclipse for building your GUI. However, Netbeans IDE allows you to design the interface as you have mentioned.
While creating the GUI manually is a good idea, if you want to speed up the process, you would need to use an IDE.If you are not restricted to Eclipse and want to use an IDE, I would suggest Netbeans.
Upvotes: 1