Hi. I am having a problem laying out a gui. I want to place five buttons and five labels on a panel. I want the button to have a corresponding label. I can do this with Grid Layout. However, I want the buttons to be small. Grid Layout will not let me set the size of the buttons. What would be the best way of going about this? I'm pretty new with layout managers so bear with me (I was using visual age before to do GUI!). Thanks a million!
Hi Jennifer, The beauty of java is that you can do it many different ways. See the code below to see how to do it using two different layout approaches.
Null layouts totally loose out on the dynamic resize features of layout managers. I have never worked on UI code that at some point did not need some kind of modification. If you hard code every position and size on your screen, you have a TON of extra work to add a button here or a combo box there. Don't use null layouts. Learn to harness the power of LayoutManager!!!
I have yet to see a UI that has to use the null layout. Once you use it, you also have to set the resizing of your window to off. If you don't, you have to place a great deal of code into your app just to make it appear proportional to where you started. The Layout Managers provide all of this functionality for you. The argument has been made many times in this forum against the use of null layout. It is a broken record. The difference between the null layout and the others is that it takes time to learn the other layouts and how they can be combined to do whatever you want. We can also talk about adding new components to an existing layout. Using the null all components need to be repositioned manually. With the other layout managers you may just need to add the component. If you need more argements against the use of null layout, just search this forum. There are plenty against. Now why don't you provide an argument for their use.