Layout Manager Question


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Layout Manager Question

  1. #1
    Join Date
    Nov 2002
    Posts
    3

    Question Layout Manager Question

    I'm having a little difficulty in grasping layout managers as they apply to containers. I understand what layout managers do and are for but I've been hashing over one particular instance involving a JFrame and a tabbed pane inside the JFrame.

    What I've got is a JFrame with FlowLayout() assigned. Inside the JFrame, I've placed a tabbed pane with six tabs. Within each tab I would like to assign a grid layout for some JRadio buttons I've designed. My question is this:

    Can I assign one layout manager to the JFrame while assigning a different one to the individual panes of the tabbed pane? By the way, is an individual tab of a tabbed pane considered a container? If the answers to my questions are yes, would someone please provide me with an example of something similar to what I've described?

    Thank you for your advice.

  2. #2
    Join Date
    Dec 2002
    Posts
    17
    Adding panels within panels are limitless, you don't necessarily have to use difficult layout managers, if you keeping adding panels within panels, you can usualy get what you want. For example the following:


    import javax.swing.*;
    import java.awt.*;
    public class YourCrap extends JFrame
    {

    JTextField someTextField = new JTextField(10);
    JTextArea someTextArea = new JTextArea(5,4);
    JButton button1 = new JButton("Button1");
    JButton button2 = new JButton("Button2");
    JButton button3 = new JButton("Button3");

    YourCrap() // default constructor
    {
    JPanel yourPanel = new JPanel();
    yourPanel.setLayout(new FlowLayout());
    yourPanel.add(someTextField);
    yourPanel.add(someTextArea);

    JPanel yourDadPanel = new JPanel();
    yourDadPanel.setLayout(new GridLayout(4,4,2,2));
    yourDadPanel.add(button1);
    yourDadPanel.add(button2);
    yourDadPanel.add(button3);
    yourDadPanel.add(yourPanel);

    JPanel yourMomPanel = new JPanel();
    yourMomPanel.setLayout(new BorderLayout());
    yourMomPanel.add(yourDadPanel, BorderLayout.SOUTH);

    getContentPane().setLayout(new FlowLayout());
    getContentPane().add(yourMomPanel);
    }
    public static void main(String[] args)
    {
    YourCrap yc = new YourCrap();
    yc.setTitle("Your Crap");
    yc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    yc.pack();
    yc.setVisible(true);
    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center