problems with addGap(int) in GroupLayout.Group
This is the snippet :
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));
These are the errors produced on cmd :
MainPageTypo.java:27: cannot find symbol
logoPanel.setHorizontalGroup((GroupLayout.Alignment.BASELINE).addGap(100,100));
开发者_如何学Go ^
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
Why it is giving these errors and how can i solve them?
According to the JavaDoc GroupLayout.Group only has methods addGap(int)
and addGap(int, int, int)
so you're either missing one parameter or have one too much.
addGap(100)
should thus be sufficient.
Edit 2:
You're calling addGap(...)
on GroupLayout.Alignment
which is an enum and doesn't provide that method at all: line 28 contains (GroupLayout.Alignment.BASELINE).addGap(100,100)
I think you want to call logoLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
or logoLayout.createSequentialGroup()
to create a group.
You're also calling setHorizontalGroup(...)
(and setVerticalGroup(...)
) on the JPanel and not on the GroupLayout which should also generate errors. Change that to logoLayout.setHorizontalGroup( ... );
.
Edit: a short hint on what the message means
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
I suggest you also correct the code snippet to a correct form, which is in the code you provided.
From what I see you get:
IllegalStateException: Baseline must be used along vertical axis
It mean the first parallel group cannot be created on baseline change it e.g. to LEADING. And it compiles.
精彩评论