This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi All! im a Graphics designer before a Java programmer , therefor i need to layout my interface in a very flexibility way. when i extending a component i use setLayout(null) and setBounds() to path the component to very specific place on the extended component. i wonder if you (all) can suggust me a way that can provide flexbility in pathing the components , for example: the BorderLayout() can be pathing to a specific place by setting add(com,BorderLayout.East) but it has only 5 places and not according to my requests, how can GridLayout path? and the other manager? thanks
It depends on what you want and need. Multiple panels with different layouts works great. The key is knowing how each layout reacts and what combination to use. I don't use null layout because when you expand the viewing area or the change resolution you often get ugly results. I have had good results using BoxLayout with multiple panels stacked. GridBagLayout, BorderLayout and FlowLayout they all have their place.
Joined: Sep 03, 2001
Hi guys! ok...but what about pathing them to a specific position in the managet? only in BorderLayout i can do it ny East,South etc.. how can i do the samr think with the others??? thanks?
Joined: May 17, 2001
I am not sure what you mean. I generally look at the screen mock up and break it into logical pieces. For instance you may have a header area, a group of aligned text fields and labels, another grouping of components and at the bottom buttons. I may decide to create a separate panel for each logical group. All of those I decide to place on the main window using a vertical BoxLayout. The header panel I use FlowLayout centered. The text/label fields GridBagLayout. The buttons FlowLayout centered. It all comes down to knowing how each layout works and acts when you change the size of the window. If you use the layout managers correctly the components aren't placed in an absolute position they are placed relative to others and the layout manger takes care of it. If you use the null layout, when you resize a window it can really look bad. So you decide i'll make it so it can't be resized. Then the resolution is changed and it looks bad again. Play with the layout managers putting various components on them and see what happens. You will get to the point where you can look at screen mock ups and know where to break it up and what layout to use. There is no easy answer.
Here is a tutorial to help you understand: http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html Normaly you need to use more than one to get any complex layout. For instance you can take a Frame and give it a GridLayout of 2 by 3. Then EACH of those 6 spots can have a Panel in them. Each of the Panels can then have whatever LayoutManager that you want IT to have, etc. Stacking containers gives you LOTS of combinations of ways to format the screen. It just depends on how clever and artistic you are in designing the arrangements.
"JavaRanch, where the deer and the Certified play" - David O'Meara