Hi,
I am using panel.setLocation(int, int); in my program but it doesn't affect anything, is there any other method that can help me change the location of a panel within another larger panel?
Thanks.
Printable View
Hi,
I am using panel.setLocation(int, int); in my program but it doesn't affect anything, is there any other method that can help me change the location of a panel within another larger panel?
Thanks.
Could u send the code withj codetag so that we can see and give solution?
The best way to set the location of JPanels and other components is to let the layout managers do the heavy lifting for you. I recommend (if you haven't done so already) that you have a look at the layout manager tutorials. Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)
Hello,
true Furable is right!!!
you could try using : FlowLayout, GridLayout, BoxLayout They are easy to use.
... on the other hand: suppose the OP wants to create a card game where the cards (JPanels with an image) float around freely in their parent container. Remove the LayoutManager from the parent container and whenever a JPanel is repositioned call revalidate() on it.
kind regards,
Jos
Only component using LayoutManagers require the use of revalidate(). If you don't use a LayoutManager then you are responsible for setting the size/location of the component. That is why the recommendation is to always use a layout manager so you can invoke revalidate() and you don't have to worry about all the minor details.Quote:
Remove the LayoutManager from the parent container and whenever a JPanel is repositioned call revalidate() on it.