File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Changing Layout of a Panel in Border Layout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Changing Layout of a Panel in Border Layout" Watch "Changing Layout of a Panel in Border Layout" New topic
Author

Changing Layout of a Panel in Border Layout

vinay jain
Greenhorn

Joined: Nov 07, 2001
Posts: 27
Hello Everybody
Lets see if I can summarize the situation in few lines.
I have a JFrame with BorderLayout, In the SOUTH part of the FRAME I have a Panel with 4 buttons, I want to change the layout of CENTER Panel based on the button pressed in the SOUTH section. e.g. I might want to change the centerPanel from BorderLayout to GridLayout or something like that. I tried to do that but it is not working. I am posting the code below that I used. Please help me it is driving me nuts, not understanding why the code is behaving like it is.
Thanks

Results:
1. On initial screen if I press Next Button it works like it is suppose to.
2. If I press Previous button the centerPanel becomes blank. WHY??
3. If I press the next button after pressing previous button the centerPanel remains blank. WHY???
4. If I press prev, next, next then the second next makes the centerPanel like it is suppose to.
Help PLEASE!!!
Vinay
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Vinay,
You are very close. Instead of removing and adding the center component use the invalidate/validate methods of the Container. I have altered your code to work and I am showing it to you below. The commented lines are not required and the bold ones are added to make it work.

Regards,
Manfred.
vinay jain
Greenhorn

Joined: Nov 07, 2001
Posts: 27
Hi Manfred
THANKS A LOT!!!. I was going crazy.
Vinay
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Changing Layout of a Panel in Border Layout
 
Similar Threads
JButtons switching states(icons) too quickly
Accessing JFrame contents
what layouts to use
Standalone app worked... as Applet does not.
calling another swing application to run when a button is click from my swing application