java left logo
java middle logo
java right logo
 

Home arrow Java SE Tips
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4101
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to use Swing BoxLayout E-mail
User Rating: / 113
PoorBest 

The box layout is of two types: Horizontal and Vertical. Horizontal layout place the components from left to right in a container and Vertical layout places the components from top to button. Unlike in the GridLayout, the Box Layout allows components to occupy different amount of space.

This sample code shows the use of BoxLayout of Vertical type. It arranges four buttons in a vertical column.


Image

import java.awt.Component;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.WindowConstants;

public class BoxLayoutExp extends JFrame {
    
    public BoxLayoutExp() {
        
        setTitle("Box Layout Example");
        setSize(150150);
        getContentPane().setLayout(
                new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
        
        JButton btn1 = new JButton("Button 1");
        JButton btn2 = new JButton("Button 2");
        JButton btn3 = new JButton("Button 3");
        
        JButton btn4 = new JButton("Button 4");
        getContentPane().add(btn1);
        getContentPane().add(btn2);
        btn1.setAlignmentX(Component.CENTER_ALIGNMENT);
        getContentPane().add(btn3);
        getContentPane().add(btn4);
    }
    public static void main(String[] args) {
        
        BoxLayoutExp ble = new BoxLayoutExp();
        ble.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        ble.setVisible(true);
        
    }
}

 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.