在出现JScrollPane时遇到问题

时间:2019-03-16 01:52:23

标签: java swing jscrollpane

因此,我一直在尽可能地排除故障,但是我只想创建一个函数,该函数将接收缓冲流,然后在可滚动窗格中显示该缓冲流的内容。但是,每次我运行它时,窗口根本不会显示。我想知道我在这里做错了什么。

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);
    }

谢谢您的帮助。

1 个答案:

答案 0 :(得分:2)

在此行代码中,您将JTextArea替换为空的JPanel作为JScrollPane的视口:

scrollableScreen.setViewportView(makeScreenAppear);

这就是为什么您看不到文字的原因。不需要JPanel。只需将JScrollPane添加到顶级窗口-我假设它是JFrameJDialog

相关问题