Swing을 처음 사용하므로 Java 자습서 및 API를 읽습니다. 나는 JComponent
(DTPicture
- 드래그 앤 드롭 지원)의 서브 클래스로 놀아왔다. 기본적으로 GridLayout
으로 패널을 만듭니다. 그런 다음 패널에 DTPicture
개체를 채 웁니다. DTPicture
은 getLocation()
을 상속했습니다. 그러나이 값을 호출하면 값은 0입니다. 그러나 GUI를 실행하면 DTPicture
개체가 세로로 스팬됩니다. 그렇다면 getLocation
은 왜 0을 반환합니까?JComponent를 추가 할 때 getY()가 반환됩니다.
감사합니다.
아래 코드는 입니다. * 다른 모든 것은 초기화되고 선언되고 구현되었습니다. 컴포넌트가 생성 될 때
public class RackBuilderTool extends JPanel{
//maps rack slot # to DTPicture location on JPanel
public static Point[] slotIDArray = new Point[42];
public RackBuilderTool() {
super(new GridLayout(42, 1));
//DTPicture[] rackSlotArray = new DTPicture[42];
for (int i = 0; i < 42; i++) {
//add(new ComponentLabel());
DTPicture temp = new DTPicture(null);
System.out.println(add(temp).getLocation());
//address of DTPicture Component
slotIDArray[i] = temp.getLocation();
}
}
[This] (http://www.java2s.com/Tutorial/Java/0240__Swing/HowtoUseGridLayout.htm)는 귀하의 노력을 지원해야합니다. –