JFrame 및 "this"라는 키워드에 문제가 있습니다. frame.getContentPane을 사용할 때 프레임을 "this"로 바꾸지 않으면 구성 요소가 표시되지 않습니다. getContentPane이 JFrame 내용 창을 가져 오지 않는 것 같아요, 다른 내용을 얻었습니다. 두 가지 JFrame 구성 요소가 하나만 있다고하더라도 두려워합니다. 아무도이 문제를 설명 할 수 있습니까?
이 내 코드입니다 :
JFrame을 사용할 때 구성 요소가 표시되지 않습니다.
public class Form1 extends JFrame
{
private static final long serialVersionUID = 1L;
JFrame frame = new JFrame("TableLayout");
Container content = frame.getContentPane();//this doesn't work unless I replace "frame" with the key word "this"///
public Form1()//constructor
{
String label[] = {"Top", "Bottom", "Add", "Delete", "Center", "Overlap"};
double border = 5;
double size[][] =
{{border, 0.20, border, TableLayout.FILL, border, 0.80, border}, // Columns
{border, 0.15, border, TableLayout.FILL, border, 0.10, border}}; // Rows
JButton button[] = new JButton[label.length];
for (int i = 0; i < label.length; i++)
{
button[i] = new JButton(label[i]);
}
content.add (button[0], "1, 1, 5, 1"); // Top (row,column)
content.add (button[1], " 1, 5, 5, 5"); // Bottom
content.add ((button[2], "1, 3 "); // Left
content.add (button[3],"5, 3, "); // Right
this.pack();
}
}
을 슬프게도, 나는 한 번 다시 동안보다이 더 했어 고맙습니다. :-) – trashgod