-
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.
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks