Skip to content

Commit

Permalink
8236839: System menubar removed when other menubars are created or mo…
Browse files Browse the repository at this point in the history
…dified

Reviewed-by: kcr, aghaisas
  • Loading branch information
jkaving authored and kevinrushforth committed Feb 7, 2020
1 parent 21d3b7e commit a74137a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,8 @@ private void rebuildUI() {
setSystemMenu(stage);
}
} else {
if (curMBSkin != null && curMBSkin.getSkinnable() != null &&
if (getSkinnable().isUseSystemMenuBar() &&
curMBSkin != null && curMBSkin.getSkinnable() != null &&
curMBSkin.getSkinnable().isUseSystemMenuBar()) {
curMBSkin.getSkinnable().setUseSystemMenuBar(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package test.javafx.scene.control.skin;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import com.sun.javafx.menu.MenuBase;
import com.sun.javafx.stage.WindowHelper;
Expand All @@ -37,6 +38,7 @@
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.stage.Stage;

import java.util.List;
Expand Down Expand Up @@ -163,6 +165,35 @@ public class MenuBarSkinTest {
}
}

@Test public void testModifyingNonSystemMenuBar() {
if (tk.getSystemMenu().isSupported()) {
// Set system menubar to true
menubar.setUseSystemMenuBar(true);

// Create a secondary menubar that is not
// a system menubar
MenuBar secondaryMenuBar = new MenuBar(
new Menu("Menu 1", null, new MenuItem("Item 1")),
new Menu("Menu 2", null, new MenuItem("Item 2")));
secondaryMenuBar.setSkin(new MenuBarSkin(secondaryMenuBar));

// Add the secondary menubar to the scene
((Group)scene.getRoot()).getChildren().add(secondaryMenuBar);

// Verify that the menubar is the system menubar
assertTrue(menubar.isUseSystemMenuBar());

// Remove a menu from the secondary menubar
// to trigger a rebuild of its UI and a call
// to the sceneProperty listener
secondaryMenuBar.getMenus().remove(1);

// Verify that this has not affected whether the
// original menubar is the system menubar
assertTrue(menubar.isUseSystemMenuBar());
}
}

public static final class MenuBarSkinMock extends MenuBarSkin {
boolean propertyChanged = false;
int propertyChangeCount = 0;
Expand Down

0 comments on commit a74137a

Please sign in to comment.