-
Bug
-
Resolution: Fixed
-
P3
-
1.0
-
1.0.2
-
x86
-
windows_nt
-
Verified
Solaris only: repeatedly removing and setting menuBar causes the menubar area not to be
drawn. This is somewhat intermittant, it may take a couple of times to reproduce.
Steps to reproduce
Compile and run attached code.
Press <No Menu>
Press <Main Menu>
Press <No Menu>
Press <Main Menu>
// Note: sometimes pressing the No Menu button twice before pressing Main menu
will cause problem.
// Menu Bar Tests.
import java.awt.*;
public class MenuBarTest extends AppFrame
{
private MenuBar mainMenuBar;
private MenuBar otherMenuBar;
private final String OTHER_MENU = "Other Menu";
private final String MAIN_MENU = "Main Menu";
private final String NO_MENU = "No Menu";
public MenuBarTest(String title, boolean bSouthPanel)
{
super(title);
// local variables
Menu tempMenu;
// create main menu
tempMenu = new Menu("Main Menu");
tempMenu.add("New");
tempMenu.addSeparator();
tempMenu.add("Exit");
mainMenuBar = new MenuBar();
mainMenuBar.add(tempMenu);
setMenuBar(mainMenuBar);
// create other menu
tempMenu = new Menu("Other Menu");
tempMenu.add("Save");
tempMenu.addSeparator();
tempMenu.add("Exit");
otherMenuBar = new MenuBar();
otherMenuBar.add(tempMenu);
// create button panel
Panel tempPanel = new Panel();
tempPanel.add( new Button(NO_MENU) );
tempPanel.add( new Button(MAIN_MENU) );
tempPanel.add( new Button(OTHER_MENU) );
add( "North", tempPanel );
add( "Center", new TextArea(100, 100) );
if (bSouthPanel)
{
tempPanel = new Panel();
tempPanel.add( new Label("South Panel") );
add( "South", tempPanel );
}
resize(400, 400);
}
public boolean action(Event evt, Object obj)
{
// local variables
String label;
MenuBar tempMenu;
if (evt.target instanceof Button)
{
tempMenu = getMenuBar();
label = (String) obj;
if ( label.equals(NO_MENU) )
{
if ( tempMenu != null )
remove( tempMenu );
}
else if ( label.equals(MAIN_MENU) )
{
if ( tempMenu != null )
remove ( tempMenu );
setMenuBar(mainMenuBar);
}
else if ( label.equals(OTHER_MENU) )
{
if ( tempMenu != null )
remove ( tempMenu );
setMenuBar(otherMenuBar);
show();
}
else
return false;
return true;
}
else
return super.action(evt, obj);
}
public static void main(String args[])
{
// local variables
boolean bSouthPanel = false;
// check arguments
if ( (args.length > 0) && ( args[0].equals("-South") ) )
bSouthPanel = true;
AppFrame f = new MenuBarTest("Menu Bar Test", bSouthPanel);
f.show();
}
}
/* Generic Full Application Frame
* @(#)AppFrame.java 1.4 15 Nov 1995 15:48:24
* @author Kevin A. Smith
*
* The class AppFrame provides an AWT Frame window for running
* applications.
*
*/
import java.awt.Frame;
import java.awt.Event;
import java.awt.MenuItem;
// Application Frame window
class AppFrame extends Frame
{
// constructor needed to pass window title to class Frame
public AppFrame(String name)
{
// call java.awt.Frame(String) constructor
super(name);
}
// needed to allow window close
public boolean handleEvent(Event e)
{
// Window Destroy event
if (e.id == Event.WINDOW_DESTROY)
return appExit(0);
// it's good form to let the super class look at any
// unhandled events
return super.handleEvent(e);
} // end handleEvent()
// Generic Action event handler
public boolean action(Event evt, Object obj)
{
if(evt.target instanceof MenuItem)
return menuEvent(evt, obj);
else
// it is good form to let the super class look at any
// unhandled events.
return super.action(evt, obj);
} // end action()
// Generic Menu event handler
public boolean menuEvent(Event evt, Object obj)
{
String menuLabel = obj.toString();
if( menuLabel.equals("Exit") )
{
// This menu item is the same as Close
return appExit(0);
}
else
// menu event handler did nothing with this event.
// In a fully written application, you should never
// get to this line.
return false;
} // end menuEvent()
// application exit code
protected boolean appExit(int exitCode)
{
System.exit(exitCode);
return true;
}
} // end class AppFrame
drawn. This is somewhat intermittant, it may take a couple of times to reproduce.
Steps to reproduce
Compile and run attached code.
Press <No Menu>
Press <Main Menu>
Press <No Menu>
Press <Main Menu>
// Note: sometimes pressing the No Menu button twice before pressing Main menu
will cause problem.
// Menu Bar Tests.
import java.awt.*;
public class MenuBarTest extends AppFrame
{
private MenuBar mainMenuBar;
private MenuBar otherMenuBar;
private final String OTHER_MENU = "Other Menu";
private final String MAIN_MENU = "Main Menu";
private final String NO_MENU = "No Menu";
public MenuBarTest(String title, boolean bSouthPanel)
{
super(title);
// local variables
Menu tempMenu;
// create main menu
tempMenu = new Menu("Main Menu");
tempMenu.add("New");
tempMenu.addSeparator();
tempMenu.add("Exit");
mainMenuBar = new MenuBar();
mainMenuBar.add(tempMenu);
setMenuBar(mainMenuBar);
// create other menu
tempMenu = new Menu("Other Menu");
tempMenu.add("Save");
tempMenu.addSeparator();
tempMenu.add("Exit");
otherMenuBar = new MenuBar();
otherMenuBar.add(tempMenu);
// create button panel
Panel tempPanel = new Panel();
tempPanel.add( new Button(NO_MENU) );
tempPanel.add( new Button(MAIN_MENU) );
tempPanel.add( new Button(OTHER_MENU) );
add( "North", tempPanel );
add( "Center", new TextArea(100, 100) );
if (bSouthPanel)
{
tempPanel = new Panel();
tempPanel.add( new Label("South Panel") );
add( "South", tempPanel );
}
resize(400, 400);
}
public boolean action(Event evt, Object obj)
{
// local variables
String label;
MenuBar tempMenu;
if (evt.target instanceof Button)
{
tempMenu = getMenuBar();
label = (String) obj;
if ( label.equals(NO_MENU) )
{
if ( tempMenu != null )
remove( tempMenu );
}
else if ( label.equals(MAIN_MENU) )
{
if ( tempMenu != null )
remove ( tempMenu );
setMenuBar(mainMenuBar);
}
else if ( label.equals(OTHER_MENU) )
{
if ( tempMenu != null )
remove ( tempMenu );
setMenuBar(otherMenuBar);
show();
}
else
return false;
return true;
}
else
return super.action(evt, obj);
}
public static void main(String args[])
{
// local variables
boolean bSouthPanel = false;
// check arguments
if ( (args.length > 0) && ( args[0].equals("-South") ) )
bSouthPanel = true;
AppFrame f = new MenuBarTest("Menu Bar Test", bSouthPanel);
f.show();
}
}
/* Generic Full Application Frame
* @(#)AppFrame.java 1.4 15 Nov 1995 15:48:24
* @author Kevin A. Smith
*
* The class AppFrame provides an AWT Frame window for running
* applications.
*
*/
import java.awt.Frame;
import java.awt.Event;
import java.awt.MenuItem;
// Application Frame window
class AppFrame extends Frame
{
// constructor needed to pass window title to class Frame
public AppFrame(String name)
{
// call java.awt.Frame(String) constructor
super(name);
}
// needed to allow window close
public boolean handleEvent(Event e)
{
// Window Destroy event
if (e.id == Event.WINDOW_DESTROY)
return appExit(0);
// it's good form to let the super class look at any
// unhandled events
return super.handleEvent(e);
} // end handleEvent()
// Generic Action event handler
public boolean action(Event evt, Object obj)
{
if(evt.target instanceof MenuItem)
return menuEvent(evt, obj);
else
// it is good form to let the super class look at any
// unhandled events.
return super.action(evt, obj);
} // end action()
// Generic Menu event handler
public boolean menuEvent(Event evt, Object obj)
{
String menuLabel = obj.toString();
if( menuLabel.equals("Exit") )
{
// This menu item is the same as Close
return appExit(0);
}
else
// menu event handler did nothing with this event.
// In a fully written application, you should never
// get to this line.
return false;
} // end menuEvent()
// application exit code
protected boolean appExit(int exitCode)
{
System.exit(exitCode);
return true;
}
} // end class AppFrame