Home arrow static arrow Java Programming [Archive] - box container and grid layout
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - box container and grid layout
This topic has 2 replies on 1 page.

Posts:130
Registered: 6/8/04
box container and grid layout  
Jul 9, 2004 10:00 PM



 
(1) i do not have a compiler available to test this theory.

can we have a box container (say vertical) that contains multiple components (buttons, etc) inside a grid cell?
 

Posts:4,906
Registered: 23/07/02
Re: box container and grid layout  
Jul 12, 2004 7:28 AM (reply 1 of 2)



 
Not directly. However, you can add a panel to a grid cell and then add multiple components to the panel.
 

Posts:2,384
Registered: 3/16/01
Re: box container and grid layout  
Jul 12, 2004 11:21 AM (reply 2 of 2)



 
Looking at the api for the Box class, Box descends from JComponent. This compiles and runs okay.
import java.awt.*;import javax.swing.*; public class BoxTest{    public static void main(String[] args)    {        JComponent            vertical = Box.createVerticalBox(),            horizontal = Box.createHorizontalBox();        for(int j = 0; j < 4; j++)        {            vertical.add(Box.createVerticalGlue());            vertical.add(new JButton("button " + (j + 1)));            vertical.add(Box.createVerticalGlue());            horizontal.add(Box.createHorizontalGlue());            horizontal.add(new JButton("button " + (j + 5)));            horizontal.add(Box.createHorizontalGlue());        }        JPanel panel = new JPanel(new GridBagLayout());        GridBagConstraints gbc = new GridBagConstraints();        gbc.weightx = 1.0;        gbc.weighty = 1.0;        gbc.fill = gbc.BOTH;        gbc.gridwidth = gbc.REMAINDER;        panel.add(vertical, gbc);        panel.add(horizontal, gbc);        JFrame f = new JFrame();        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        f.getContentPane().add(panel);        f.setSize(400,400);        f.setLocation(200,200);        f.setVisible(true);    }}
 
This topic has 2 replies on 1 page.