Results 1 to 6 of 6

Thread: What is the use of Box class?

  1. #1
    Join Date
    Dec 2009
    Posts
    48

    What is the use of Box class?

    Hello friend,

    I need you help to sort-out my query which is related to the java classes. I want to be aware about the 'Box class' of java programming. I don't know anything about the use of Box class. I have referred many java book for Box class, but nothing was helpful. I wonder if you are able to provide me some information about the Box class of java along with suitable example for the same. I am waiting for your reply.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,949

    Re: What is the use of Box class?

    Box class is a lightweight container that uses a BoxLayout object as its layout manager. Box provides several class methods that are useful for containers using BoxLayout - even non-Box containers. The Box class can create several kinds of invisible components that affect layout: glue, struts, and rigid areas. If all the components your Box contains have a fixed size, you might want to use a glue component (returned by createGlue) to control the components' positions.

  3. #3
    Join Date
    May 2008
    Posts
    2,015

    Re: What is the use of Box class?

    Hi friend,

    I suggest you to refer following example of 'Box class', which will give you something idea about the use of this class:
    Code:
    import javax.swing.Box;
    import javax.swing.JButton;
    import javax.swing.JTextField;
    
    public class BoxDM
     {
      public static void main(String argsw[]) {
        JFrame verticalFrame1 = new JFrame("Vertical");
        verticalFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Box verticalBox1 = Box.createVerticalBox();
        verticalBox1.add(new JLabel("Top"));
        verticalBox1.add(new JTextField("Middle"));
        verticalBox1.add(new JButton("Bottom"));
        verticalFrame1.add(verticalBox, BorderLayout.CENTER);
        verticalFrame1.setSize(250, 150);
        verticalFrame1.setVisible(true);
    
      }
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,302

    Re: What is the use of Box class?

    Please review following some of the important methods of 'Box class':
    • setLayout(LayoutManager lm)
    • getAccessibleContext()
    • createVerticalStrut(int height1)
    • createRigidArea(Dimension dm)
    • createHorizontalStrut(int width1)
    • createHorizontalGlue()

  5. #5
    Join Date
    Oct 2005
    Posts
    2,394

    Re: What is the use of Box class?

    In following example I have used different methods of Box class of java:
    Code:
    import javax.swing.Box;
    import javax.swing.JTextField;
    
    public class SampleBox
    
     {
      public static void main(String argvs[])
     {
        JFrame hf = new JFrame("Horizontal");
        hf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
        Box hb = Box.createHorizontalBox();
    
        hb.add(new JLabel("Left"));
        hb.add(new JTextField("Middle"));
        hb.add(new JButton("Right"));
     
        hf.add(hb, BorderLayout.CENTER);
        hf.setSize(150, 150);
        hf.setVisible(true);
      }
    
    }

  6. #6
    Join Date
    May 2008
    Posts
    2,393

    Re: What is the use of Box class?

    Hello friend,

    If you want to use the properties of Box class, then you need to be aware about the following nested classes:
    1. Component.BltBufferStrategy
    2. Box.AccessibleBox
    3. Container.AccessibleAWTContainer
    4. Component.FlipBufferStrategy
    5. JComponent.AccessibleJComponent

Similar Threads

  1. Replies: 8
    Last Post: 08-10-2011, 11:06 PM
  2. Replies: 4
    Last Post: 03-01-2011, 09:44 PM
  3. Replies: 5
    Last Post: 12-02-2010, 05:23 PM
  4. Ultra solid drives:Imation M-Class and S-Class
    By Regina in forum Portable Devices
    Replies: 1
    Last Post: 03-04-2009, 10:34 AM
  5. Good news for CBSE CLASS X & CLASS IX - visit learnnext
    By surya_expert in forum Education Career and Job Discussions
    Replies: 0
    Last Post: 13-12-2008, 11:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •