Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



What is the use of Box class?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 20-02-2010
Member
 
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.

Reply With Quote
  #2  
Old 20-02-2010
Member
 
Join Date: Apr 2008
Posts: 1,944
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.
Reply With Quote
  #3  
Old 20-02-2010
Member
 
Join Date: May 2008
Posts: 2,001
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);

  }
}
Reply With Quote
  #4  
Old 20-02-2010
Member
 
Join Date: May 2008
Posts: 2,283
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()
Reply With Quote
  #5  
Old 20-02-2010
Member
 
Join Date: Oct 2005
Posts: 2,385
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);
  }

}
Reply With Quote
  #6  
Old 20-02-2010
Member
 
Join Date: May 2008
Posts: 2,373
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What is the use of Box class?"
Thread Thread Starter Forum Replies Last Post
Upgrade Sony Ericsson Xperia Play Micro SD card from class 2 8GB to class 4 32GB Aaryan2011 Portable Devices 8 08-10-2011 11:06 PM
What is the difference between Local class and global class in C++? Dėfrim Software Development 4 03-01-2011 09:44 PM
How to initialize a derived class with an instance of the base class in c#? KAIRU26 Software Development 5 12-02-2010 05:23 PM
Ultra solid drives:Imation M-Class and S-Class Regina Portable Devices 1 03-04-2009 10:34 AM
Good news for CBSE CLASS X & CLASS IX - visit learnnext surya_expert Education Career and Job Discussions 0 13-12-2008 11:09 AM


All times are GMT +5.5. The time now is 06:51 PM.