• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JMenu

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1.In my applet I added lot of menu items in my submenuitem named "More".
It goes out of my appletViewer screen and could not able see the menu items.
And also it goes out of browser's bottom side.
2. And also I am having probem with menuitem's visibility.
When I click the menu the menuitems goes behind the previously drawed image. Presently I managed using
paintComponents(g) method.
I don't know how to add the menubar in a specific layer. I tried to implement the same program
in Applet, it is working fine and also the menu items adjust itself and shows all the menuitems within
the applet canvas area.
If any code available it is very useful.
Here is the full code: Please read it and advice me. Thanks in advance.

import com.sun.java.swing.JApplet;
import com.sun.java.swing.JTextField;
import com.sun.java.swing.JMenu;
import com.sun.java.swing.JMenuItem;
import com.sun.java.swing.JMenuBar;
import com.sun.java.swing.JScrollPane;
import com.sun.java.swing.JToolBar;
import com.sun.java.swing.JButton;
import com.sun.java.swing.border.BevelBorder;
import com.sun.java.swing.ImageIcon;
import com.sun.java.swing.plaf.windows.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import java.net.InetAddress;
import java.net.URL;
import java.net.MalformedURLException;
import com.sun.java.swing.UIManager;
import java.awt.Color;
public class Reports extends JApplet implements ActionListener,MouseListener{
String name;
URL url,urls;
Dimension pt;
JMenuBar bar;
JMenu menu,menu1,temp1,temp2;
JScrollPane jpane;
JMenuItem menuitem;
int num;
Image img;
boolean pnt;
public void init() {
try {
UIManager.setLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
}
catch (Exception e) {}
num=0;
pnt=false;
urls=null;
jpane=new JScrollPane();;
pt=Toolkit.getDefaultToolkit().getScreenSize();
url=getCodeBase();
this.setSize(pt);
bar=new JMenuBar();
this.getContentPane().setLayout(new FlowLayout());
menusetup();
setJMenuBar(bar);
}
public void menusetup(){
menu = bar.add(new JMenu("Masters"));
menu.addMouseListener(this);
menu.setName("main");
menu.setAutoscrolls(true);
menu.setFont(new Font("Times New Roman",Font.PLAIN,12));
menu.setMnemonic('M');
menuitemadd(menu,"Cash Posting Accounts",'A');
menuitemadd(menu,"Data Classifications",'l');
menuitemadd(menu,"Billing Modules",'B');
menuitemadd(menu,"Collection Agency",'o');
menuitemadd(menu,"Diagnosis Master",'B');
menuitemadd(menu,"Doctor Master",'o');
menuitemadd(menu,"Doctor Facility Listing",'B');
menuitemadd(menu,"Employer Master",'o');
menuitemadd(menu,"EDI Master",'B');
menuitemadd(menu,"Facility Master",'o');
menuitemadd(menu,"Insurance Master",'B');
menuitemadd(menu,"Insurance Specific Modifier",'o');
submenuitemadd("More",'P');
menuitemadd(menu1,"Insurance Mandatory Fields",'M');
menuitemadd(menu1,"Insurance Facility #",'M');
menuitemadd(menu1,"Modifier List",'M');
temp1=menu1;
subsubmenuitemadd(temp1,"Claim Form Design",'i');
temp2=menu1;
menu1=temp1;
menuitemadd(temp2,"Claim Specific Rules Master",'M');
menuitemadd(temp2,"Claim Form Mapping",'x');
menuitemadd(temp2,"Claim Form Pringing Rules",'x');
menuitemadd(menu1,"Locum Doctor",'t');
menuitemadd(menu1,"Place of Service",'t');
menuitemadd(menu1,"Manual and News Letters Details",'t');
menuitemadd(menu1,"Modification Log",'t');
menuitemadd(menu1,"Patient/Insurance",'t');
menuitemadd(menu1,"Patient Type Master",'t');
menuitemadd(menu1,"Procedure Master",'M');
menuitemadd(menu1,"Procedure Slot",'t');
menuitemadd(menu1,"Procedure Code Slot",'t');
menuitemadd(menu1,"Provider",'t');
menuitemadd(menu1,"Reasons",'t');
menuitemadd(menu1,"Rules Listing",'t');
menuitemadd(menu1,"Status Listing",'t');
menuitemadd(menu1,"Zip Code",'t');
menu = bar.add(new JMenu("Financials"));
menu.addMouseListener(this);
menu.setName("main");
menu.setFont(new Font("Times New Roman",Font.PLAIN,12));
menu.setMnemonic('F');
menu = bar.add(new JMenu("Analysis"));
menu.addMouseListener(this);
menu.setName("main");
menu.setFont(new Font("Times New Roman",Font.PLAIN,12));
menu.setMnemonic('A');
menu = bar.add(new JMenu("Service Analysis Reports"));
menu.addMouseListener(this);
menu.setName("main");
menu.setFont(new Font("Times New Roman",Font.PLAIN,12));
menu.setMnemonic('e');
menu = bar.add(new JMenu("Production"));
menu.addMouseListener(this);
menu.setName("main");
menu.setFont(new Font("Times New Roman",Font.PLAIN,12));
menu.setMnemonic('P');
menu = bar.add(new JMenu("Transaction Reports"));
menu.addMouseListener(this);
menu.setName("main");
menu.setFont(new Font("Times New Roman",Font.PLAIN,12));
menu.setMnemonic('T');
menu = bar.add(new JMenu("Others"));
menu.addMouseListener(this);
menu.setName("main");
menu.setFont(new Font("Times New Roman",Font.PLAIN,12));
menu.setMnemonic('O');
menu = bar.add(new JMenu("Exit"));
menu.addMouseListener(this);
menu.setName("Exit");
menu.setFont(new Font("Times New Roman",Font.PLAIN,12));
menu.setMnemonic('x');
}
public void menuitemadd(JMenu jmenu,String mnuItem,char underscore){
menuitem=jmenu.add(new JMenuItem(mnuItem,underscore));
menuitem.setFont(new Font("Times New Roman",Font.PLAIN,12));
menuitem.addActionListener(this);
menuitem.setName("mnu" + num);
num++;
}
public void submenuitemadd(String submenuItem,char underscore){
menu1=new JMenu(submenuItem);
menu.add(menu1);
menu1.setMnemonic(underscore);
menu1.setFont(new Font("Times New Roman",Font.PLAIN,12));
}
public void subsubmenuitemadd(JMenu jmnu,String submenuItem,char underscore){
menu1=new JMenu(submenuItem);
jmnu.add(menu1);
menu1.setMnemonic(underscore);
menu1.setFont(new Font("Times New Roman",Font.PLAIN,12));
}
public void actionPerformed(ActionEvent e){
JMenuItem item;
name="";
item=(JMenuItem)e.getSource();
name=item.getName();
if(name.equals("Exit"))
{
try{
urls=new URL("My URL ADDRESS");}
catch(MalformedURLException ex){}
getAppletContext().showDocument(urls);
return;
}
img=getImage(url,name + ".gif");
pnt=true;
repaint();
}
public void paint(Graphics g){
if(pnt==true)
{
this.paintComponents(g);
int wid=img.getWidth(this);
int hei=img.getHeight(this);
g.drawImage(img,(pt.width-wid)/2,(pt.height-hei)/2,wid,hei,this);
}
else
this.paintComponents(g);
}
public void mouseClicked(MouseEvent evt)
{}
public void mouseEntered(MouseEvent evt)
{}
public void mouseExited(MouseEvent evt)
{}
public void mousePressed(MouseEvent evt)
{
pnt=false;
repaint();
}
public void mouseReleased(MouseEvent evt)
{}
}
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you running this applet inside a JFrame,
if you are you need to getContentPane() of
the applet and add the menujbar or do a
setJMenubar on the applet not the JFrame.
I had this problem with one of my JApplets.
the Applet is Layered on top of the JFrame

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic