Ive read up on the different type of Layouts available to Java and am wondering if it would be best to not have one at all.
Question I have initially is do the Layouts only affect buttons or can they affect print strings and photo’s also?
Ive read up on the different type of Layouts available to Java and am wondering if it would be best to not have one at all.
Question I have initially is do the Layouts only affect buttons or can they affect print strings and photo’s also?
Layout managers affect all non-window components (Button, Canvas, List, TextField, etc, etc).
Without layout-manager you can do absolute positioning of components, but be aware that it will most likely look completely crap and unprofessional on other systems than yours. So always use layout managers, unless… hm… I can’t think of a reason not to.
Good luck with your GUIs, and don’t forget to read the javadocs/guide from sun.
Without layout managers you also generally dont resize well.
BUT if we are talkign abotu games then mnost dont use ANY Swing or AWT at all beyond AWT buffer flipping (assuming we are talkign about a 2D game. A 3D game, and even some 2D games dont use AWT at all but just render through OGL)
If you are having trouble understanding LayoutManagers, there is a tutorial on Sun’s Java site that explains it all very well.
http://java.sun.com/developer/onlineTraining/GUI/AWTLayoutMgr/index.html
Ive read the entire javadoc on the different layout managers. But thanx for the extra info. What I can’t deside is… My first Java project has been a simple 2 player battle applet that works pretty well for text. I just added a background image to it that defines areas where the players/monster pictures are supposed to be, the status objects such as HP, Hit, DMG, the 3 buttons (Attack, Reset, Exit), and the Status window which im hoping to use for a scrolling history of hit, misses, and damage dealt.
But after reading the different layout managers that java uses. I can’t figure out a way beyond not using any at all that I could position these items where I want them. And i guess considering that the applet will never be bigger then the size i set it as in my applet tags on the html page then it shouldn’t distort.
After the layout is done i will start working on DB connectivity
that should be fun! But for now I’m really not sure what to use to lay it out. Also since everywhere I read they are saying to use a layout manager… how do i define where my buttons and such are supposed to go if i setLayout (null); ??
If you’re using null-layout, you’re placing your buttons etc. with setBounds(…).
Would you happen to have a good visual example of using a null layout and setbounds to determine where the objects go and where to utilize the setbounds and such?
Most of the time you aren’t going to be able to achieve the results you want by by attemptinig to layout all of the components with a single LayoutManager. What you have to do is make use of Panel objects. Look at the layout you’re after and see how components can logically be grouped together in different areas of the screen. Divide the window up along the lines of those component groups. For each group, create a Panel and add the components of that group to the Panel. Each Panel object will use its own LayoutManager to get its components in the right positions within the Panel. With the components properly positioned in each Panel you can use a single LayoutManager to position the Panels appropriately within the frame. Using this technique you can easily create some complex layouts.
You can also have multiple nested panels. That is why I pointed you to that particular tutorial. It gives a lot of good tips on how to use the LayoutManagers together to achieve what you want. After I read that tutorial, I could create any layout that I wanted.
Same for me. I use nested Panel with all kinds of LayoutManagers everywhere.
Still it feels like a huge hassle, compared to DnD in… say… Delphi.
The big advantage of layout managers is that resizing happens nicely and automatically.
The price you pay is more work to set it up.
If you want DnD there are a ton of GUI layout editors out there. If you dont want the layout manager functionality just leave it null and voilla you have DnD placement.
I finally got it figured out with the no Layout Manager
Desided that since its an applet there shouldn’t be any resizing and I really need absolute positioning. Thanx for the help as always.
Forever the Java Noob!
-Me