Jump to content
  • Advertisement
Sign in to follow this  
fantasyme

[java] borderlayout ?question

This topic is 3085 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am new to java. Now, I use borderlayout command to set my objects layout. However, as I searched on internet + read in the book. North, South, East, West and Center are alinment that I can set? only? I have around 10~ objects. Is it possible to use borderlayout for my project? If I use borderlayout(CENTER) for 2 objects, I found that 2 objects are overlapped. Do you have any suggestion?

Share this post


Link to post
Share on other sites
Advertisement
It all depends on what kind of layout you are trying to go for. But in order to support more than 5 components using a BorderLayout you need to nest your objects (components) inside other containers (JPanel usually).

GridBagLayout is a necessary layout for non-nested forms. If you use a null layout i.e. setLayout(null) you can position your components to absolute values meaning that where you setPosition(x,y) is where they will appear, but they won't move or resize if the window is resizable or if it's container is resized.

A combination of FlowLayout, BorderLayout, CardLayout, and GridLayout is usually good for a start but eventually you will enjoy using GridBagLayout for flexibility and significantly shorter amount of code and nested components.

BorderLayout will only allow a single component to occupy one direction, i.e. there can only be one component in the NORTH spot.

see the LayoutManager interface java docs for a list of available layouts.

I would familiarize yourself with as many as possible. It also isn't that difficult to make your own layout manager.

Also you can get a good deal of information reading some of Sun's Java Tutorials they have them for just about anything, their not entirely geared toward professional level applications but they cover the basic usage of the sdk classes. They have one for layout managers Using Layout Managers it would definitely help to at least check out example code or read through it.



Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!