gpt4 book ai didi

java - GroupLayout.Group 中 addGap(int) 的问题

转载 作者:行者123 更新时间:2023-11-29 07:19:55 25 4
gpt4 key购买 nike

这是片段:

JPanel logoPanel=new JPanel();
GroupLayout logoLayout=new GroupLayout(logoPanel);
logoPanel.setLayout(logoLayout);
logoPanel.setHorizontalGroup((GroupLayout.Alignment.BASELINE).addGap(100,100));
logoPanel.setVerticalGroup((GroupLayout.Alignment.BASELINE).addGap(100,100));

这些是在 cmd 上产生的错误:

MainPageTypo.java:27: cannot find symbol
logoPanel.setHorizontalGroup((GroupLayout.Alignment.BASELINE).addGap(100,100));
^
symbol: method addGap(int,int)
location: class Alignment
MainPageTypo.java:28: cannot find symbol
logoPanel.setVerticalGroup((GroupLayout.Alignment.BASELINE).addGap(100,100));
^
symbol: method addGap(int,int)
location: class Alignment
2 errors

为什么会出现这些错误,我该如何解决?

最佳答案

根据JavaDoc GroupLayout.Group 只有 addGap(int)addGap(int, int, int) 方法,因此您要么缺少一个参数,要么参数过多。

addGap(100) 因此应该足够了。

编辑 2:

您在 GroupLayout.Alignment 上调用 addGap(...),这是一个枚举,根本不提供该方法:第 28 行包含 (GroupLayout.Alignment.BASELINE).addGap(100,100)

我想你想调用 logoLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)logoLayout.createSequentialGroup() 来创建一个组。

您还在 JPanel 而不是 GroupLayout 上调用 setHorizo​​ntalGroup(...)(和 setVerticalGroup(...)),这也会产生错误.将其更改为 logoLayout.setHorizo​​ntalGroup( ... );

编辑:关于消息含义的简短提示

symbol:   method addGap(int,int)   //the symbol that is searched for
location: class Alignment //the symbol (method) is searched in class Alignment or its class hierarchy
MainPageTypo.java:28: cannot find symbol //the compiler cant find the symbol stated above which is used at line 28 in file MainPageTypo.java
logoPanel.setVerticalGroup((GroupLayout.Alignment.BASELINE).addGap(100,100)); // this is the content of line 28

关于java - GroupLayout.Group 中 addGap(int) 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5910080/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com