NULL Layout

Sometimes getting components onto your applet or application in the exact location you desire is a maddening process. One way of dealing with the situation is to set the layout to NULL:

      setLayout(null);


Using null Layout: The following code illustrates how to use null layout. The first thing you have to do is set the Layout to null. The second thing you have to do is manually set the location of the item. Finally you have to set the size of the item. If you have a lot of components, you have to do a lot of repetitious work.


Dealing With Lots of Components: Sometimes you have a lot of components to place on a page, but they are arranged in orderly rows or some other pattern. Here's a little example:


Choice: Study the first example on this page and make sure that you can use the Choice component. You may need this one in the future. Also notice the embedded for-loop in the second example. Familiarize yourself with it, but you may or may not understand it at this point. But, FYI, the outer loop counts from 10 to 320 by 70. The inner loop counts from 10 to 180 by 30. So, the outer loop iterates five times since the increment is performed AFTER the iteration. The inner loop iterates six times. This gives us a total of 5x6=30 iterations for the code contained inside the loop. Each time setLocation is called either x and/or y has a different value.