所以我一直在尽可能地对此进行故障排除,但我只是想创建一个函数来接受缓冲流,然后在可滚动窗格中显示该缓冲流的内容。但是每次我运行它时窗口根本不显示。我想知道我在这里做错了什么。
void show(BufferedOutputStream showFileContent)
{
String fileContent = showFileContent.toString();
JTextArea content = new JTextArea(fileContent);
JScrollPane scrollableScreen = new JScrollPane(content);
JPanel makeScreenAppear = new JPanel(new BorderLayout());
scrollableScreen.setViewportView(makeScreenAppear);
scrollableScreen.setVisible(true);
scrollableScreen.setSize(500,400);
}
谢谢您的帮助。
您正在使用空JTextArea
替换JPanel
作为代码的这一行中JScrollPane
的视口:
scrollableScreen.setViewportView(makeScreenAppear);
这就是你没看到文字的原因。不需要JPanel
。简单地将JScrollPane
添加到顶层窗口 - 我假设是JFrame
或JDialog
。