aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Menu question? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Menu question? " Watch "Menu question? " New topic
Author

Menu question?

Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
Hello
I wrote small java application that works:
import javax.swing.* ;
public class User_Case extends JFrame {
public static void main(String args[]){
new User_Case().show();
}
JToolBar tb ;
JButton sigB,invB,nandB,norB,andB,orB ;
Scrollbar sbV, sbH ;
public User_Case(){
super("User Cases");
setBackground( Color.white);
sbV = new Scrollbar(Scrollbar.VERTICAL, 0, 5, 0, 500 );
getContentPane().add( sbV, BorderLayout.EAST );
sbH = new Scrollbar(Scrollbar.HORIZONTAL, 0,5, 0,500 );
getContentPane().add( sbH, BorderLayout.SOUTH );

JPanel cenP = new JPanel();
getContentPane().setBackground(Color.white) ;
cenP.setBackground( Color.white );
getContentPane().add( cenP, BorderLayout.CENTER );

tb = new JToolBar() ;
tb.setBorderPainted( true );
tb.add(sigB = new JButton(new ImageIcon("button.jpg")) );
tb.add(invB = new JButton(new ImageIcon("button.jpg")) );
tb.add(nandB = new JButton(new ImageIcon("button.jpg")) );

tb.setFloatable( true );
tb.add(norB = new JButton(new ImageIcon("button.jpg")) );
tb.add(andB = new JButton(new ImageIcon("button.jpg")) );
tb.add(orB = new JButton(new ImageIcon("button.jpg")) );
getContentPane().add( tb, BorderLayout.NORTH );

//PROBLEM START
Menu fileMenu = new Menu("File");
fileMenu.add("New");
fileMenu.add("Open...");
fileMenu.addSeparator();
fileMenu.add("Close");
fileMenu.add("Save");
fileMenu.add("Save As...");
fileMenu.addSeparator();
fileMenu.add("Page Setup...");
fileMenu.add("Print");
fileMenu.addSeparator();
fileMenu.add("Quit");
add(fileMenu); //ERROR


setSize( 900, 700 ); // initial width, height
setLocation( 20,20 );
}
}
When I add thiscode it gives me an erros.

Menu fileMenu = new Menu("File");
fileMenu.add("New");
fileMenu.add("Open...");
fileMenu.addSeparator();
fileMenu.add("Close");
fileMenu.add("Save");
fileMenu.add("Save As...");
fileMenu.addSeparator();
fileMenu.add("Page Setup...");
fileMenu.add("Print");
fileMenu.addSeparator();
fileMenu.add("Quit");
add(fileMenu); //ERROR
Can someone give me an advice?
Thanks
[ August 07, 2002: Message edited by: Mike Shn ]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Well, at first glance, Menu it an AWT component and looks like you are writing in Swing. So you should use a JMenu instead. Second, you need to create a JMenuBar and add your JMenu Components to it. Then you say addJMenuBar(myMenuBar) instead of add(fileMenu).


GenRocket - Experts at Building Test Data
Tom Hughes
Ranch Hand

Joined: Feb 09, 2002
Posts: 86
instead of

try this

Tom
ravindran shanmugam
Greenhorn

Joined: Aug 30, 2001
Posts: 15
Try this,
I've made two changes.
1) Include import java.awt.*;
2) adding the menu to a menubar and then setting the menubar to the JFrame.
**********************************************
import javax.swing.*;
import java.awt.*;
public class User_Case extends JFrame {
public static void main(String args[]){
new User_Case().show();
}
JToolBar tb ;
JButton sigB,invB,nandB,norB,andB,orB ;
Scrollbar sbV, sbH ;
public User_Case(){
super("User Cases");
setBackground( Color.white);
sbV = new Scrollbar(Scrollbar.VERTICAL, 0, 5, 0, 500 );
getContentPane().add( sbV, BorderLayout.EAST );
sbH = new Scrollbar(Scrollbar.HORIZONTAL, 0,5, 0,500 );
getContentPane().add( sbH, BorderLayout.SOUTH );
JPanel cenP = new JPanel();
getContentPane().setBackground(Color.white) ;
cenP.setBackground( Color.white );
getContentPane().add( cenP, BorderLayout.CENTER );
tb = new JToolBar() ;
tb.setBorderPainted( true );
tb.add(sigB = new JButton(new ImageIcon("button.jpg")) );
tb.add(invB = new JButton(new ImageIcon("button.jpg")) );
tb.add(nandB = new JButton(new ImageIcon("button.jpg")) );
tb.setFloatable( true );
tb.add(norB = new JButton(new ImageIcon("button.jpg")) );
tb.add(andB = new JButton(new ImageIcon("button.jpg")) );
tb.add(orB = new JButton(new ImageIcon("button.jpg")) );
getContentPane().add( tb, BorderLayout.NORTH );
//PROBLEM START
Menu fileMenu = new Menu("File");
MenuBar mb = new MenuBar();
fileMenu.add("New");
fileMenu.add("Open...");
fileMenu.addSeparator();
fileMenu.add("Close");
fileMenu.add("Save");
fileMenu.add("Save As...");
fileMenu.addSeparator();
fileMenu.add("Page Setup...");
fileMenu.add("Print");
fileMenu.addSeparator();
fileMenu.add("Quit");
mb.add(fileMenu);
setMenuBar(mb);
//add(fileMenu); //ERROR
setSize( 900, 700 ); // initial width, height
setLocation( 20,20 );
}
}
- Ravindran.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Menu question?