首页 > 解决方案 > JComponent 无法初始化:java.lang.IllegalArgumentException:宽度和高度必须 >= 0

问题描述

我有一个使用 install4j 创建的安装程序,它在包含安装目录选择器组件的屏幕上根本无法显示除背景图像之外的任何内容,据我从堆栈跟踪中可以看出,该组件是基于 Swing JComponent 的。

该问题仅发生在特定的 Windows Server 2016 服务器上,并且我从未测试过其他环境。同一屏幕上还有其他组件,但通过反复试验,我发现一旦禁用/不构建上述 JComponent/Directory 选择器,一切都会正常显示。

这是堆栈跟踪:

java.lang.IllegalArgumentException: Width and height must be >= 0
    at java.awt.Component.getBaseline(Unknown Source)
    at javax.swing.JComponent.getBaseline(Unknown Source)
    at java.awt.GridBagLayout.calculateBaseline(Unknown Source)
    at java.awt.GridBagLayout.GetLayoutInfo(Unknown Source)
    at java.awt.GridBagLayout.getLayoutInfo(Unknown Source)
    at java.awt.GridBagLayout.preferredLayoutSize(Unknown Source)
    at java.awt.Container.preferredSize(Unknown Source)
    at java.awt.Container.getPreferredSize(Unknown Source)
    at javax.swing.JComponent.getPreferredSize(Unknown Source)
    at java.awt.BorderLayout.preferredLayoutSize(Unknown Source)
    at java.awt.Container.preferredSize(Unknown Source)
    at java.awt.Container.getPreferredSize(Unknown Source)
    at javax.swing.JComponent.getPreferredSize(Unknown Source)
    at java.awt.GridBagLayout.GetLayoutInfo(Unknown Source)
    at java.awt.GridBagLayout.getLayoutInfo(Unknown Source)
    at java.awt.GridBagLayout.preferredLayoutSize(Unknown Source)
    at java.awt.Container.preferredSize(Unknown Source)
    at java.awt.Container.getPreferredSize(Unknown Source)
    at javax.swing.JComponent.getPreferredSize(Unknown Source)
    at com.install4j.runtime.beans.screens.components.ScrollablePanel.getPreferredScrollableViewportSize(ScrollablePanel.java:13)
    at javax.swing.ViewportLayout.preferredLayoutSize(Unknown Source)
    at java.awt.Container.preferredSize(Unknown Source)
    at java.awt.Container.getPreferredSize(Unknown Source)
    at javax.swing.JComponent.getPreferredSize(Unknown Source)
    at javax.swing.ScrollPaneLayout.preferredLayoutSize(Unknown Source)
    at java.awt.Container.preferredSize(Unknown Source)
    at java.awt.Container.getPreferredSize(Unknown Source)
    at javax.swing.JComponent.getPreferredSize(Unknown Source)
    at java.awt.BorderLayout.preferredLayoutSize(Unknown Source)
    at java.awt.Container.preferredSize(Unknown Source)
    at java.awt.Container.getPreferredSize(Unknown Source)
    at javax.swing.JComponent.getPreferredSize(Unknown Source)
    at java.awt.GridBagLayout.GetLayoutInfo(Unknown Source)
    at java.awt.GridBagLayout.getLayoutInfo(Unknown Source)
    at java.awt.GridBagLayout.preferredLayoutSize(Unknown Source)
    at java.awt.Container.preferredSize(Unknown Source)
    at java.awt.Container.getPreferredSize(Unknown Source)
    at javax.swing.JComponent.getPreferredSize(Unknown Source)
    at java.awt.GridBagLayout.GetLayoutInfo(Unknown Source)
    at java.awt.GridBagLayout.getLayoutInfo(Unknown Source)
    at java.awt.GridBagLayout.preferredLayoutSize(Unknown Source)
    at java.awt.Container.preferredSize(Unknown Source)
    at java.awt.Container.getPreferredSize(Unknown Source)
    at javax.swing.JComponent.getPreferredSize(Unknown Source)
    at java.awt.BorderLayout.preferredLayoutSize(Unknown Source)
    at java.awt.Container.preferredSize(Unknown Source)
    at java.awt.Container.getPreferredSize(Unknown Source)
    at javax.swing.JComponent.getPreferredSize(Unknown Source)
    at java.awt.GridBagLayout.GetLayoutInfo(Unknown Source)
    at java.awt.GridBagLayout.getLayoutInfo(Unknown Source)
    at java.awt.GridBagLayout.preferredLayoutSize(Unknown Source)
    at java.awt.Container.preferredSize(Unknown Source)
    at java.awt.Container.getPreferredSize(Unknown Source)
    at javax.swing.JComponent.getPreferredSize(Unknown Source)
    at java.awt.BorderLayout.preferredLayoutSize(Unknown Source)
    at java.awt.Container.preferredSize(Unknown Source)
    at java.awt.Container.getPreferredSize(Unknown Source)
    at javax.swing.JComponent.getPreferredSize(Unknown Source)
    at java.awt.GridBagLayout.GetLayoutInfo(Unknown Source)
    at java.awt.GridBagLayout.getLayoutInfo(Unknown Source)
    at java.awt.GridBagLayout.preferredLayoutSize(Unknown Source)
    at java.awt.Container.preferredSize(Unknown Source)
    at java.awt.Container.getPreferredSize(Unknown Source)
    at javax.swing.JComponent.getPreferredSize(Unknown Source)
    at java.awt.BorderLayout.preferredLayoutSize(Unknown Source)
    at java.awt.Container.preferredSize(Unknown Source)
    at java.awt.Container.getPreferredSize(Unknown Source)
    at javax.swing.JComponent.getPreferredSize(Unknown Source)
    at java.awt.GridBagLayout.GetLayoutInfo(Unknown Source)
    at java.awt.GridBagLayout.getLayoutInfo(Unknown Source)
    at java.awt.GridBagLayout.ArrangeGrid(Unknown Source)
    at java.awt.GridBagLayout.arrangeGrid(Unknown Source)
    at java.awt.GridBagLayout.layoutContainer(Unknown Source)
    at java.awt.Container.layout(Unknown Source)
    at java.awt.Container.doLayout(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validate(Unknown Source)
    at java.awt.CardLayout.show(Unknown Source)
    at com.install4j.runtime.wizard.WizardBase.activateScreen(WizardBase.java:138)
    at com.install4j.runtime.wizard.WizardScreen.activate(WizardScreen.java:43)
    at com.install4j.runtime.installer.frontend.ScreenEnvelope.activate(ScreenEnvelope.java:166)
    at com.install4j.runtime.wizard.WizardBase.setScreen(WizardBase.java:122)
    at com.install4j.runtime.installer.frontend.WizardScreenExecutor.execute(WizardScreenExecutor.java:293)
    at com.install4j.runtime.installer.controller.Controller$1.run(Controller.java:155)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

标签: javaswingawtinstall4jjcomponent

解决方案


它最终以某种方式与 Windows 用户权限/设置相关。

遇到此问题的安装程序/可执行用户最终使用不同的 Windows 管理员用户运行可执行文件,并且一切正常。

两个用户都是管理员用户,所以我必须更多地挖掘用户权限的差异以及它们如何影响这个问题。


推荐阅读