Results 1 to 5 of 5

Thread: Using Top-Level Containers in Java

  1. #1
    Join Date
    Aug 2006
    Posts
    155

    Using Top-Level Containers in Java

    Hi,
    I am confused while using the containers in Java. I have recently started doing the Java and completed some of the basic programs. I thought that posting my doubt over here can help me in solving the confusion.!! so please tell me how to use Top-Level Containers in Java.?? Any coding related to the topic would be grateful for me..!!
    thanks in advance.!!
    Desktop * Athlon X2 4200 | 2048M RAM | 160G HD | 7600GT
    MacMini * G4 1.33GHz | 512M RAM | 40G HD | Radeon 9200
    Laptop * Sempron 2800 | 512M RAM | 60G HD
    PDA * Dell Axim x51 | 128M Internal | 256M SD Card

  2. #2
    Join Date
    Nov 2008
    Posts
    996

    Re: Using Top-Level Containers in Java

    All elements of a user interface must be added to the content pane of a top-level container in Java 2. Also you should know that each program that uses Swing components has at least one top-level container. The top-level container is the hierarchy that contains all of the Swing components that appear inside the top-level container. You can also set the content pane to a new JPanel (but not a split, tabbed, or scroll pane) with myFrame.setContentPane(myPanel) by adding components to myPanel.

  3. #3
    Join Date
    Mar 2008
    Posts
    672

    Re: Using Top-Level Containers in Java

    Normally, you will use three types of the top-level containers. They are as follows :
    • Dialogs can easily be created. Methods in the Toolkit class should be used to get a print dialog.
    • Windows (JFrame) have a title bar with close and iconifying buttons.
    • Applets

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Using Top-Level Containers in Java

    You can use the following coding for the top-level container :
    Code:
    package components;
    
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class TopLevelDemo {
    
        private static void createAndShowGUI() {
            JFrame frame = new JFrame("TopLevelTrial");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            JMenuBar greenMenuBar = new JMenuBar();
            greenMenuBar.setOpaque(true);
            greenMenuBar.setBackground(new Color(204, 157, 142));
            greenMenuBar.setPreferredSize(new Dimension(140, 28));
    
            JLabel yellowLabel = new JLabel();
            yellowLabel.setOpaque(true);
            yellowLabel.setBackground(new Color(148, 103, 211));
            yellowLabel.setPreferredSize(new Dimension(107, 150));
    
            frame.setJMenuBar(greenMenuBar);
            frame.getContentPane().add(yellowLabel, BorderLayout.CENTER);
    
            frame.pack();
            frame.setVisible(true);
        }
    
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    }

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

    Re: Using Top-Level Containers in Java

    If you want to make a component the content pane, then you would have to use the top-level container's setContentPane method. You can see an example that I have mentioned below :

    Code:
    JPanel contentPane = new JPanel(new BorderLayout());
        contentPane.setBorder(someBorder);
        contentPane.add(someComponent, BorderLayout.CENTER);
        contentPane.add(anotherComponent, BorderLayout.PAGE_END);
    
    
        topLevelContainer.setContentPane(contentPane);

Similar Threads

  1. ADMT to transfer users and all OU containers
    By Aidy in forum Windows Server Help
    Replies: 1
    Last Post: 16-05-2011, 12:00 AM
  2. Linux Containers Tools
    By Barsha in forum Operating Systems
    Replies: 5
    Last Post: 01-04-2010, 06:32 AM
  3. What are the queue containers of the C++
    By Catcher in forum Software Development
    Replies: 4
    Last Post: 27-02-2010, 07:40 PM
  4. Don't know about Sequence Containers
    By Sonam Goenka in forum Software Development
    Replies: 5
    Last Post: 09-02-2010, 02:10 PM
  5. Default containers in AD
    By Serrix in forum Active Directory
    Replies: 7
    Last Post: 24-11-2009, 06:03 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,727,291,061.23934 seconds with 17 queries