This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reg:Component Resize

 
adeeb alexander
Ranch Hand
Posts: 268
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i have a panel with few components. I made the component layout as null. I defined the boundaries using the setBounds methos. What i need is to resize this components automatically when the window is resized. Can any body help me through it.

Thanks & Regards
alexander
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a layout manager.
 
pete stein
Bartender
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep agrees with Maneesh. Here is a link to the Sun tutorial: Laying Out Components Within a Container

My other recommendation is to learn and use the more basic layouts first such as GridLayout, BoxLayout, BorderLayout, and FlowLayout. Save the GridBagLayout for later. Also, understand that you can nest JPanels each using a different layout, and by so doing build a complex layout.

Best of luck.
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mig Layout is also being talked about.
 
adeeb alexander
Ranch Hand
Posts: 268
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying.
But i have added components using only the setBounds method. I can do with layout managers also. But main problem is that i am unable to resize components on window resize.
Is it possible to achive component resizing without any layout managers
 
pete stein
Bartender
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
adeeb alexander wrote:Thanks for replying.
But i have added components using only the setBounds method. I can do with layout managers also. But main problem is that i am unable to resize components on window resize.
Is it possible to achive component resizing without any layout managers

This my friend is one of the reasons for the existence of layout managers. For those of us who've used them, your problem is screaming for their use. I'm curious why you seemingly insist on not using the right tool for the job?
 
Campbell Ritchie
Sheriff
Pie
Posts: 47278
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only use one LayoutManager for each Container; if you set bounds, then the Components might not resize correctly and might overlap other Components which do resize.
 
adeeb alexander
Ranch Hand
Posts: 268
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heres the code which i used for arranging the components. this is actually very easy to arrange components. Easier than the layouts like grouplayout and gridbag layout. the only problem i face is the resizing of the components.

Isn't there a way to solve my problem with just few lines of code because i have written much code already.
 
pete stein
Bartender
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
adeeb alexander wrote:Heres the code which i used for arranging the components. this is actually very easy to arrange components. Easier than the layouts like grouplayout and gridbag layout. the only problem i face is the resizing of the components.

Perhaps, but much harder to adjust and enhance. For instance, what if you want to add another JTextField to your program?

Here's an example that goes against my previous rec in that it uses GridBagLayout, but I felt that I had to use this to accommodate the label you have between the JTextFields, the one that states Enter Date in....

Please run the and you'll see that it looks somewhat similar to your program:


Yes, it's a bit complex, and I'm sorry for that, but it was created in a bit of a rush. You'll notice that it is somewhat resizeable, though not very pretty when resized. This can all be tweaked.

The real power and beauty of layout managers comes when you want to extend your code. Say you'd like to add another textfield at the bottom that allows one to enter comments. In you're program, you'd have to change the location of all components below this field. In mine, all you'd have to do would be to add one String to a String array. You'd simply change this:


to this:


Try it and see.
 
adeeb alexander
Ranch Hand
Posts: 268
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much stein
I have learned a new thing now. But i will use GroupLayout as i am comfortable with it.
Thanks again
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic