This is a bug in the JMenu.setPopupMenuVisible()
Here is the workaround:
class MyMenu extends JMenu {
public MyMenu(String s) {
super(s);
}
public void setPopupMenuVisible(boolean b) {
if ( getMenuComponentCount()>0 ) {
super.setPopupMenuVisible(b);
}
}
}
--
Thanks,
Andrey.
Senaka Suriyaarachchi wrote:
>
> Hi All
> When I created the JBenuBar with JMenu having no JMenuItem it shows tiny
> pixel when I select the JMenu. Please explain me how can I avoid this.
>
> THank you in advance.
>
> BR
> Senaka
>
> /* Sample Code */
>
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
>
> public class MenuTester extends JFrame implements ActionListener {
> public void actionPerformed (ActionEvent e) {
> System.out.println (e.getActionCommand());
> }
>
> public MenuTester() {
> super ("Menu Example");
>
> JMenuBar jmb = new JMenuBar();
>
> JMenu file = new JMenu ("File");
> JMenuItem item;
> file.add (item = new JMenuItem ("New"));
> item.addActionListener (this);
> file.add (item = new JMenuItem ("Open"));
> item.addActionListener (this);
> file.addSeparator();
> file.add (item = new JMenuItem ("Close"));
> item.addActionListener (this);
> jmb.add (file);
>
> JMenu edit = new JMenu ("Edit");
> JMenuItem cut = new JMenuItem ("Cut");
> cut.addActionListener (this);
> edit.add (cut);
>
> jmb.add (edit);
>
> JMenu company = new JMenu("Company");
>
> jmb.add(company);
>
> setJMenuBar (jmb);
> }
>
> public static void main(String args[]) {
> JFrame f = new MenuTester ();
> f.setBackground (Color.lightGray);
> f.addWindowListener(new WindowAdapter() {
> public void windowClosing(WindowEvent e) {
> System.exit(0);
> }
> });
> f.setSize (300, 200);
> f.show();
> }
>
> }
> _______________________________________________
> Advanced-swing mailing list
> [EMAIL PROTECTED]
> http://eos.dk/mailman/listinfo/advanced-swing
--
Thanks,
Andrey.
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing