这是片段:

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:

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

我认为您想呼叫logoLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)logoLayout.createSequentialGroup()创建一个组。

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

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

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

10-08 01:54