Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-06-2009, 09:50 PM
Member
 
Join Date: Mar 2009
Posts: 1
Rep Power: 0
leitbug06 is on a distinguished road
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.
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();
            }
        });
    }     
}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 03-07-2009, 12:46 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,452
Rep Power: 8
Fubarable is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
menubar in splitpane masa AWT / Swing 1 12-16-2008 10:01 AM
Program using JPanel - problems doozer8688 New To Java 6 11-05-2008 12:16 AM
JPanel / layout problems Warhorsei AWT / Swing 4 06-04-2008 06:26 AM
Problems while loading a JPanel to JApplet... Ananth Chellathurai Java Applets 0 11-24-2007 11:47 AM
JPanel Problems Riftwalker AWT / Swing 6 10-16-2007 12:16 AM


All times are GMT +2. The time now is 12:48 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org