Apache NetBeans的JFrame表单GUI设计器在添加Swing菜单栏时引发异常

zlhcx6iw  于 2022-11-10  发布在  Apache
关注(0)|答案(1)|浏览(145)

此问题来自超级用户migrated,因为25天前可以在Stack Overflow. Migrated上回答。

背景

最近,我使用New project -> Java with Ant -> Java Application创建了一个新的NetBeans项目,然后创建了一个新的jFrame表单,方法是右键单击包图标(here's what it looks like),然后选择New -> JFrame form。之后,我开始从Palette选项卡添加swing组件。

问题

当我尝试在Swing Menus下添加Menu Bar时,组件被添加到框架中。但是,堆栈跟踪被直接打印到整个框架上,使得框架上的任何组件都无法看到。堆栈跟踪如下:

The following exception has been thrown during painting of the form. Use the Navigator window to fix or remove
the problematic component.
java.lang.NullPointerException: Cannot invoke "javax.swing.border.Border.paintBorder(java.awt.Component,
java.awt.Graphics, int, int, int, int)" because the return value of "com.apple.laf.AquaMenuPainter $RecyclableBorder.get(" is
null
at java.desktop/com.apple.laf.AquaMenuPainter.paintMenuBarBackground(AquaMenuPainter.java:149)
at java.desktop/com.apple.laf.AquaMenuBarUl.paint(AquaMenuBarUl.java:88)
at java.desktop/javax.swing.plaf.ComponentUl.update(ComponentUl.java:161)
at java.desktop/javax.swing.JComponent.paintComponent(Component.java:852)
at java.desktop/javax.swing.JComponent.paint(Component.java:1128)
at java.desktop/javax.swing.JComponent.paintChildren(Component.java:961)
at java.desktop/javax.swing.JComponent.paint(Component.java:1137)
at java.desktop/javax.swing.JLayeredPane.paint(LayeredPane.java:586)
at java.desktop/javax.swing.jComponent.paintChildren(Component.java:961)
at java.desktop/javax.swing.JComponent.paint(Component.java:1137)
at java.desktop/java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:39)
at java.desktop/sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:75)
at java.desktop/sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:112)
at java.desktop/java.awt.Container.paint(Container.java:2005)
atorg.netbeans.modules.form.fakepeer.FakePeerContainer.paint(FakePeerContainer.java:64)
at java.desktop/javax.swing.JComponent.paintChildren(Component.java:975)
at java.desktop/javax.swing.JComponent.paintUComponent.java:1137)
at org.netbeans.modules.form.ComponentLayer$DesignerPanel.paint(ComponentLayer.java:165)
at java.desktop/javax.swing.JComponent.paintChildren(Component.java:961)
at java.desktop/javax.swing.JComponent.paint(Component.java:1137)
at java.desktop/javax.swing.JComponent.paintChildrenUComponent.java:961)
at java.desktop/javax.swing.JComponent.paint(Component.java:1137)
at java.desktop/javax.swing.JComponent.paintChildren(Component.java:961)
at org.netbeans.modules.form.FormDesigner$1.paintChildren(FormDesigner.java:195)
at java.desktop/javax.swing.JComponent.paint(Component.java:1137)
at java.desktop/javax.swing.JLayeredPane.paint(LayeredPane.java:586)
at java.desktop/javax.swing.JComponent.paintChildren(Component.java:961)
at java.desktop/javax.swing.JComponent.paintUComponent.java:1137)
at java.desktop/javax.swing.JViewport.paint(Viewport.java:736)
at java.desktop/javax.swing.jComponent.paintChildren(Component.java:961)
at java.desktop/javax.swing.JComponent.paint(Component.java:1137)
at java.desktop/javax.swing.JComponent.paintChildren(Component.java:961)
at java.desktop/javax.swing.JComponent.paint(Component.java:1137)
atjava.desktop/javax.swing.JComponent.paintChildren(Component.java:961)
at java.desktop/javax.swing.JComponent.paint(Component.java:1137)
at java.desktop/javax.swing.JComponent.paintChildren(Component.java:961)
at java.desktop/javax.swing.JComponent.paint(Component.java:1137)
at java.desktop/javax.swing.JLayer.paint(Layer.java:476)
at java.desktop/javax.swing.plaf.LayerUl.paint(LayerUl.java:85)
at org.netbeans.core.multiview.SplitLayerUl.paint(SplitLayerUl.java:134)
at java.desktop/javax.swing.plaf.ComponentUl.update(ComponentUl.java:161)
at java.desktop/javax.swing.JComponent.paintComponent(Component.java:852)
at java.desktop/javax.swing.JLayer.paint(Layer.java:471)
at java.desktop/javax.swing.JComponent.paintChildren(Component.java:961)
at java.desktop/javax.swing.JComponent.paint(Component.java:1137)
at iava.desktop/iavax.swina.IComponent.paintChildren(IComponent.iava:961)

stacktrace中可能有更多行,但是当我试图向下滚动时(这样菜单栏在Design选项卡上就看不到了),stacktrace消失了,所有其他组件都出现了。当我向上滚动时,stacktrace再次出现,所有其他组件都消失了。这里是what it looks like(突出显示的橙子组件是菜单栏)。

既往调查

我以前搜索过其他相关问题,包括:

不幸的是,没有解决方案,我可以找到工作,以解决这个问题。

系统信息

下面是我根据NetBeans About菜单项得到的系统信息:

Product Version: Apache NetBeans IDE 15
Java: 18.0.2.1; Java HotSpot (TM) 64-Bit Server VM 18.0.2.1+1-1
Runtime: Java(M) SE Runtime Environment 18.0.2.1+1-1
System: Mac OS X version 12.4 running on x86_64; UTF-8; en_CN (nb)
User directory: /Users/bryan351018/Library/Application Support/NetBeans/15
Cache directory: /Users/bryan351018/Library/Caches/NetBeans/15

下面是java --version在命令行上的输出:

java 18.0.2.1 2022-08-18
Java(TM) SE Runtime Environment (build 18.0.2.1+1-1)
Java HotSpot(TM) 64-Bit Server VM (build 18.0.2.1+1-1, mixed mode, sharing)
l3zydbqr

l3zydbqr1#

答案

转到Options -> Appearance -> Look and Feel,将Preferred Look and Feel更改为Mac OS X,然后重新启动Apache NetBeans。

对此答案发表评论

这是一个解决方案,但它似乎是一个暂时的,因为这种外观和感觉的明亮颜色是不是很和平的人的眼睛。

相关问题