使用 JAVA SWING 堆叠数据
Stack data using JAVA SWING
我正尝试在 java swing 中使用堆栈。问题是我无法在文本区域中显示堆栈,因为它始终只显示第一个字母。
我知道如何使用堆栈和队列,但我的问题是在 swing 中使用它
如果我在控制台中打印堆栈,它工作正常。
Stack<String> stacksGUI = new Stack<>();
//Button to add data into a stack
stacksGUI.push(inputTxt.getText());
inputTxt.setText("");
inputTxt.requestFocus();
//Button to show data in a textArea
while (!stacksGUI.empty()) {
outputTxt.setText(stacksGUI.pop()+" ");
}
it always shows only the first letter.
while (!stacksGUI.empty()) {
outputTxt.setText(stacksGUI.pop()+" ");
setText(...)
替换现有文本,因此您只会看到从 Stack
弹出的最后文本。
使用 JTextArea
的 append(...)
方法将现有文本追加到文本中。
我正尝试在 java swing 中使用堆栈。问题是我无法在文本区域中显示堆栈,因为它始终只显示第一个字母。
我知道如何使用堆栈和队列,但我的问题是在 swing 中使用它
如果我在控制台中打印堆栈,它工作正常。
Stack<String> stacksGUI = new Stack<>();
//Button to add data into a stack
stacksGUI.push(inputTxt.getText());
inputTxt.setText("");
inputTxt.requestFocus();
//Button to show data in a textArea
while (!stacksGUI.empty()) {
outputTxt.setText(stacksGUI.pop()+" ");
}
it always shows only the first letter.
while (!stacksGUI.empty()) {
outputTxt.setText(stacksGUI.pop()+" ");
setText(...)
替换现有文本,因此您只会看到从 Stack
弹出的最后文本。
使用 JTextArea
的 append(...)
方法将现有文本追加到文本中。