Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java Swing

Status
Not open for further replies.

jduk

Programmer
Joined
Nov 26, 2003
Messages
4
Location
GB
I want to combine as a GUI, a menu, a toolbar and a page which loads files. I have a class called 'MenuBar' with my menu in it, but when i run the code below, I get a runtime error saying that I cannot add a window (presumbaly my menu is a window) to a container. So how do I combine all these different components (i.e. menu's toolbars, windows etc)?



class MainWindow
extends JFrame
implements ActionListener

{



public MainWindow(){


MenuBar menubar = new MenuBar();

JFrame frame = new JFrame("Main Window");
JPanel panel = new JPanel();
frame.setSize(400,400);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.getContentPane().add(menubar);
frame.pack();
frame.show();

}


public void actionPerformed( ActionEvent event )
{
System.out.println( event );
}


public static void main (String args[]){

MainWindow window = new MainWindow();


}

}
 
To set a menu bar, u shouldnot use add() method. Use setJMenuBar method instead.

LOL A ship is safe in the harbour, but that's not what it is meant for!!! LOL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top