Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

setLayout() and add() a menubar on the frame

  Asked By: Kiswar    Date: Jun 19    Category: Java    Views: 2123
  

my following codes are not compiled

frame.setLayout(flow) and

frame.add(menubar);


The full codes are as follows:-

static Frame frame = new Frame("This is frame");
public static void main(String[]args){
frame.setBounds(100,200,500,500);

frame.add(menubar);
Button button1 = new Button("Button # 1");
frame.add(button1);

Button button2 = new Button("Button # 2");
frame.add(button2);

MenuBar menubar = new MenuBar();
frame.add(menubar);

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Ellen Simpson     Answered On: Jun 19

The problem with your code is that you added MenuBar
before declaring it. I'm not sure if your way of
adding a menubar  is right/acceptable. Try using this
instead:

frame.setMenuBar(menubar);

Byt remember to declare the menubar first before
adding it.

 
Answer #2    Answered By: Patricia Johnson     Answered On: Jun 19

You must add  stuff to the Container (that contains
the frame  too - Container c=frame.getContentPane();
c.add(JButtton b); ) not to the frame...

 
Didn't find what you were looking for? Find more on setLayout() and add() a menubar on the frame Or get search suggestion and latest updates.




Tagged: