swing Java GUI 3列边框布局
我正在努力为我的班级做一个项目。我应该建立3列数据。以下是GUI类的代码:
public void displayArray(String[] wordArray) {
Container myContentPane = project1JFrame.getContentPane();
TextArea arrayArea = new TextArea();
for (int i = 0; i < wordArray.length; i++) {
if (wordArray[i] != null) {
arrayArea.append(wordArray[i] + "\n"); // add the words of the array into the TextArea
}
} //for
myContentPane.add(arrayArea, BorderLayout.WEST);
project1JFrame.setVisible(true);
} //displayArray
public void displaySortedArray(String[] wordArray) {
Container myContentPane = project1JFrame.getContentPane();
TextArea arrayArea = new TextArea();
for (int i = 0; i < wordArray.length; i++) {
if (wordArray[i] != null) {
arrayArea.append(wordArray[i] + "\n"); // add the words of the array into the TextArea
}
} //for
myContentPane.add(arrayArea, BorderLayout.CENTER);
project1JFrame.setVisible(true);
} //displaySortedArray
public void displaySortedList(WordList myList) {
Container myContentPane = project1JFrame.getContentPane();
TextArea listArea = new TextArea();
WordListIterator myIt;
listArea.setText("");
myIt = myList.reset();
while (myIt.hasNext()) {
myList.append(myIt.next() + "\n");
}
myContentPane.add(listArea, BorderLayout.EAST);
project1JFrame.setVisible(true);
}
当我试着在主程序中运行这段代码时,我只得到两列。我想要3列。我猜这和边界布局有关,但我似乎做不到。救命啊
# 1 楼答案
对我来说似乎没问题
考虑提供一个证明你的问题的runnable example。这不是一个代码转储,而是您正在做的一个示例,它突出了您所遇到的问题。这将减少混乱和更好的响应
虽然,我会考虑使用{{CD1}}…p>
更多细节请看How to Use GridLayout