Results 1 to 2 of 2
- 03-06-2009, 08:50 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 1
- Rep Power
- 0
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(); } }); } }
-
Similar Threads
-
menubar in splitpane
By masa in forum AWT / SwingReplies: 1Last Post: 12-16-2008, 09:01 AM -
Program using JPanel - problems
By doozer8688 in forum New To JavaReplies: 6Last Post: 11-04-2008, 11:16 PM -
JPanel / layout problems
By Warhorsei in forum AWT / SwingReplies: 4Last Post: 06-04-2008, 05:26 AM -
Problems while loading a JPanel to JApplet...
By Ananth Chellathurai in forum Java AppletsReplies: 0Last Post: 11-24-2007, 10:47 AM -
JPanel Problems
By Riftwalker in forum AWT / SwingReplies: 6Last Post: 10-15-2007, 11:16 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks