This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Usage of custom layout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Usage of custom layout" Watch "Usage of custom layout" New topic

Usage of custom layout

Sergey Zolotaryov

Joined: Mar 14, 2006
Posts: 26
Hello, everybody.
I have finished with locking, database and business stuff and now I am moving to the GUI part.
Though I have a solid experience in Swing, I cannot say that I'm good at using such things as GridBagLayout or SpringLayout, which are the layouts, that allow positioning components in neat grids.
I have always used 3-rd party layouts, like TableLayout, which is the best choice for GUI design 99% of the time (I wonder what idiot resists encluding this layout manager to the jdk for 10+ years).

So, my question is: can I use custom non-standard layout? I wrote it myself and can explain every single line of code in it. Will it offend the assessors, that I ignore cumbersome GridBagLayout, complex SpringLayout or ugly GridLayout? The assignment mentions that the code must be understandable and maintainable by junior developers, so I thought that using a simple TableLayout would be justified.

What do you think?
Luc Feys

Joined: Nov 21, 2005
Posts: 20
I would think the assesors would prefer seeing the standard swing layouts used. That's also the recommendation you read in the books for scjd: 'Don't try to prove you know things better than the java designers do'.

But maybe you're right. If using this layout simplifies the code, then why not use it? The only question you should ask yourself is whether the code for your 'TableLayout' is easily understandable for a junior programmer too, since in that case it would be part of 'the project' to be maintained by the junior.

Sergey Zolotaryov

Joined: Mar 14, 2006
Posts: 26
It is quite simple, I guess . Very simple algorithm which just calculates preferred column widths for the table and aligns components correspondingly.

One fact that inspired me to use custom layout was an example from jsdk - one that resides in the java_home/demo/jfc/Metalworks. There is a file which uses custom layout to accomplish the most typical task - align labels and text fields.

For a junior developer (as for any other developer), it is most important that GUI does not cause pain when you want to add a component to an existing panel.
Jason Moors
Ranch Hand

Joined: Dec 04, 2001
Posts: 188
I would recommend using a standard layout manager, I think you are adding additional complexity that isn't required for this assignment and I doubt will gain you anymore marks.

Whilst you may wanted a custom layout in the real world, I think the simple layout required for this exam can be achieved by using JPanels and layout managers like BorderLayout.

Sergey Zolotaryov

Joined: Mar 14, 2006
Posts: 26
Yes, I understand this. But border layouts cannot align labels and text fields like this:

Name _______field___
Surname _______field___

GridLayout is ugly in that respect that it makes all components equal size.
GridBagLayout is too complex even for an experienced developer. I have tried it once and will never try it again.
The same with SpringLayout.
These are the layouts, that could accomplish my simple task. But none of them does the job, if you want to keep things simple.
I have figured out that its much more simpler to implement a custom layout.
Sergey Zolotaryov

Joined: Mar 14, 2006
Posts: 26
BTW, is there anybody on this forum who passed SCJD and used custom layout manager for the assignment?
Sergey Zolotaryov

Joined: Mar 14, 2006
Posts: 26
I have abandoned the idea of custom layout Spent half an hour in netbeans playing with the GridBagLayout and contraints and finally figured out how to use it effectively.
Consider Paul's rocket mass heater.
subject: Usage of custom layout
Similar Threads
ScrollPane trouble
Placing components with Swing
So many Layouts?
Newbie, Absolute Layout Question
Is this a TableLayout bug?