Results 1 to 2 of 2
  1. #1
    leitbug06 is offline Member
    Join Date
    Mar 2009
    Posts
    1
    Rep Power
    0

    Default Problems with setting the menubar and a JPanel visible

    I am creating a menu that has a JMenuBar, a JPanel with a JTextArea, and a JPanel two JButtons. When I run the code, the only thing i see is the panel with the text area and I cannot figure out why the menubar and the other panel are not visible. Any help would be greatly appreciated.
    Java Code:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class ProductDatabase extends JFrame implements ActionListener
    {    
        private JPanel textPanel;
        private JPanel buttonPanel;
        private JPanel aboutTextPanel;
        private JButton searchButton;
        private JButton editButton;
        private JTextArea textArea;
        private JTextArea aboutTextArea;
        private JInternalFrame aboutFrame;
        private JMenuBar menuBar;
        private JMenu file;
        private JMenu help;
        private JMenuItem quit;
        private JMenuItem about;
        private JMenuItem helpMI;
        private JDesktopPane desktop;
        private Container c;
        private static final int WIDTH = 400;
        private static final int HEIGHT = 300;
        private EditGUI editGUI;
        private SearchGUI searchGUI;
    
        /*
         * Sets up the main screen GUI 
         */
        
        public ProductDatabase()
        {
                super("Product Database");
                desktop = new JDesktopPane();
                setTitle("Product Database");
                setSize(WIDTH, HEIGHT);
                setVisible(true);
                setDefaultCloseOperation(EXIT_ON_CLOSE);
                c = getContentPane();
                c.setLayout(new FlowLayout());
                c.add(textPanel);
                c.add(buttonPanel);
                c.add(aboutTextPanel);
                
                  editGUI = new EditGUI();
                  searchGUI = new SearchGUI();
                  
               textPanel = new JPanel();        
               textArea = new JTextArea("Floor Coverings International \n Virginia Beach");
                textArea.setFont(new Font("serif", Font.BOLD, 12));
                textPanel.add(textArea);
                
                 buttonPanel = new JPanel();
                 searchButton = new JButton("Search");
                searchButton.setVerticalTextPosition(AbstractButton.SOUTH);
              searchButton.setHorizontalTextPosition(AbstractButton.LEADING);
              searchButton.setFont(new Font("serif", Font.PLAIN, 12));
               searchButton.addActionListener(this);
               buttonPanel.add(searchButton);
                    
               editButton = new JButton("Edit");
               editButton.setVerticalTextPosition(AbstractButton.SOUTH);
              editButton.setHorizontalTextPosition(AbstractButton.TRAILING);
              editButton.setFont(new Font("serif", Font.PLAIN, 12));
              editButton.addActionListener(this);
              buttonPanel.add(editButton); 
                  
                 aboutTextPanel = new JPanel();       
                 aboutTextArea = new JTextArea("Floor Coverings International \n Virginia Beach \n Created by: Ali Jacob");
               aboutTextArea.setFont(new Font("serif",Font.PLAIN, 12));
               aboutTextPanel.add(aboutTextArea);
                
                file = new JMenu("File");
               help = new JMenu("Help");
               quit = new JMenuItem("Quit");
               about = new JMenuItem("About");
               helpMI = new JMenuItem("Help");
                
               file.add(quit);
               help.add(about);
               help.addSeparator();
               help.add(helpMI);
                
               menuBar = new JMenuBar();
               menuBar.add(file);
               menuBar.add(help);
                
                setJMenuBar(menuBar);
    
                createJInternalFrames();
        }
        
        /*
         * Creates the JInternalFrame for the GUI
         */
        
        private void createJInternalFrames()
        {
            aboutFrame = new JInternalFrame();        
            aboutFrame = new JInternalFrame("About");
             aboutFrame.setVisible(false);
          aboutFrame.setResizable(true);
          aboutFrame.setClosable(true);
          aboutFrame.setMaximizable(true);
          aboutFrame.setIconifiable(true);
           aboutFrame.add(aboutTextPanel);
        }
    
        
        public void actionPerformed(ActionEvent e)
        {
            if(e.getSource() == searchButton)
            {
                searchGUI = new SearchGUI();
                searchGUI.setVisible(true);
            }
            
            else if(e.getSource() == editButton)
            {
                editGUI = new EditGUI();
                editGUI.setVisible(true);
            }
            
            else if(e.getSource() == quit)
            {
                System.exit(0);
            }
            
            else if(e.getSource() == about)
            {
                aboutFrame.setVisible(true);
            }
        }
        
        /*
         * Runs the GUI
         */
        
        public static void main(String[] args)
        {
            javax.swing.SwingUtilities.invokeLater(new Runnable()
            {
                public void run()
                {
                    ProductDatabase pd = new ProductDatabase();
                }
            });
        }     
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Lots of problems here, but one of the biggest is that you appear to be trying to use components before initializing them. Are nullpointerexceptions being thrown? You should be seeing these due to the above errors.

Similar Threads

  1. menubar in splitpane
    By masa in forum AWT / Swing
    Replies: 1
    Last Post: 12-16-2008, 09:01 AM
  2. Program using JPanel - problems
    By doozer8688 in forum New To Java
    Replies: 6
    Last Post: 11-04-2008, 11:16 PM
  3. JPanel / layout problems
    By Warhorsei in forum AWT / Swing
    Replies: 4
    Last Post: 06-04-2008, 05:26 AM
  4. Problems while loading a JPanel to JApplet...
    By Ananth Chellathurai in forum Java Applets
    Replies: 0
    Last Post: 11-24-2007, 10:47 AM
  5. JPanel Problems
    By Riftwalker in forum AWT / Swing
    Replies: 6
    Last Post: 10-15-2007, 11:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •