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.
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.
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 MetalworksDocumentFrame.java 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.
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.
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.
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.
Post by:autobot
grapes are vegan food pellets. Eat this tiny ad:
a bit of art, as a gift, the permaculture playing cards