Skip to content

Commit a74137a

Browse files
jkavingkevinrushforth
authored andcommitted
8236839: System menubar removed when other menubars are created or modified
Reviewed-by: kcr, aghaisas
1 parent 21d3b7e commit a74137a

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

modules/javafx.controls/src/main/java/javafx/scene/control/skin/MenuBarSkin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,8 @@ private void rebuildUI() {
866866
setSystemMenu(stage);
867867
}
868868
} else {
869-
if (curMBSkin != null && curMBSkin.getSkinnable() != null &&
869+
if (getSkinnable().isUseSystemMenuBar() &&
870+
curMBSkin != null && curMBSkin.getSkinnable() != null &&
870871
curMBSkin.getSkinnable().isUseSystemMenuBar()) {
871872
curMBSkin.getSkinnable().setUseSystemMenuBar(false);
872873
}

modules/javafx.controls/src/test/java/test/javafx/scene/control/skin/MenuBarSkinTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package test.javafx.scene.control.skin;
2727

2828
import static org.junit.Assert.assertEquals;
29+
import static org.junit.Assert.assertTrue;
2930

3031
import com.sun.javafx.menu.MenuBase;
3132
import com.sun.javafx.stage.WindowHelper;
@@ -37,6 +38,7 @@
3738
import javafx.scene.Scene;
3839
import javafx.scene.control.Menu;
3940
import javafx.scene.control.MenuBar;
41+
import javafx.scene.control.MenuItem;
4042
import javafx.stage.Stage;
4143

4244
import java.util.List;
@@ -163,6 +165,35 @@ public class MenuBarSkinTest {
163165
}
164166
}
165167

168+
@Test public void testModifyingNonSystemMenuBar() {
169+
if (tk.getSystemMenu().isSupported()) {
170+
// Set system menubar to true
171+
menubar.setUseSystemMenuBar(true);
172+
173+
// Create a secondary menubar that is not
174+
// a system menubar
175+
MenuBar secondaryMenuBar = new MenuBar(
176+
new Menu("Menu 1", null, new MenuItem("Item 1")),
177+
new Menu("Menu 2", null, new MenuItem("Item 2")));
178+
secondaryMenuBar.setSkin(new MenuBarSkin(secondaryMenuBar));
179+
180+
// Add the secondary menubar to the scene
181+
((Group)scene.getRoot()).getChildren().add(secondaryMenuBar);
182+
183+
// Verify that the menubar is the system menubar
184+
assertTrue(menubar.isUseSystemMenuBar());
185+
186+
// Remove a menu from the secondary menubar
187+
// to trigger a rebuild of its UI and a call
188+
// to the sceneProperty listener
189+
secondaryMenuBar.getMenus().remove(1);
190+
191+
// Verify that this has not affected whether the
192+
// original menubar is the system menubar
193+
assertTrue(menubar.isUseSystemMenuBar());
194+
}
195+
}
196+
166197
public static final class MenuBarSkinMock extends MenuBarSkin {
167198
boolean propertyChanged = false;
168199
int propertyChangeCount = 0;

0 commit comments

Comments
 (0)