void
JXMenuBar::WidthChanged()
{
	if (itsMenus->IsEmpty() || itsIgnoreWidthChangedCount > 0)
		{
		return;
		}

	itsIgnoreWidthChangedCount++;

	// put all menus back in menubar

	ClearOverflowMenu();

	// check if menus fit on menubar

	const JRect ap = GetAperture();

	JXMenu* m   = itsMenus->LastElement();
	JRect frame = m->GetFrame();
	if (frame.xcenter() < ap.right)
		{
		assert( itsIgnoreWidthChangedCount > 0 );
		itsIgnoreWidthChangedCount--;
		return;
		}

	// create menu to hold overflow

	JXImage* image = new JXImage(GetDisplay(), jx_down_chevron);
	assert( image != NULL );

	JXTextMenu* overflowMenu =
		new JXTextMenu(image, kJTrue, this, kFixedLeft, kFixedTop, 0,0, 10,10);
	assert( overflowMenu != NULL );
	overflowMenu->SetUpdateAction(JXMenu::kDisableNone);

	overflowMenu->SetMenuBar(this);		// don't show down arrow at right of title
	const JCoordinate extraWidth = overflowMenu->GetFrameWidth();
	overflowMenu->SetMenuBar(NULL);

	// move menus to overflow menu

	while (frame.right > ap.right - extraWidth)
		{
		const JString& title = m->GetTitleText();
		if (title.IsEmpty())
			{
			break;
			}

		overflowMenu->PrependItem(title);
		overflowMenu->AttachSubmenu(1, m);
		if (itsMenus->IsEmpty())
			{
			break;
			}

		m     = itsMenus->LastElement();
		frame = m->GetFrame();
		}

	if (overflowMenu->IsEmpty())
		{
		delete overflowMenu;
		overflowMenu = NULL;
		}
	else
		{
		AppendMenu(overflowMenu);
		itsOverflowMenu = overflowMenu;
		}

	assert( itsIgnoreWidthChangedCount > 0 );
	itsIgnoreWidthChangedCount--;
}