jQuery in Action, 2nd edition*
The moose likes Swing / AWT / SWT and the fly likes JMenu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JMenu" Watch "JMenu" New topic
Author

JMenu

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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)
{}
}
Rick Lowe
Greenhorn

Joined: Sep 24, 1999
Posts: 2
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

 
GeeCON Prague 2014
 
subject: JMenu