JScrollPane in Java

青春壹個敷衍的年華 提交于 2019-12-02 08:56:26
scrollPane.setViewportView(textArea);
scrollPane.setViewportView(imad);

Only one component can be added to the viewport of the scroll pane, so the label replaces the text area.

content.add(textArea);
content.add(imad);

A component can only have a single parent. The above code removes the label from the scrollpane, so nothing is now in the scrollpane.

Try something like:

JScrollPane = new JScrollPane( textArea );
JPanel content = new JPanel( new BorderLayout() );
content.add(scrollPane, BorderLayout.CENTER);
content.add(imad, BorderLayout.PAGE_END);
setContentPane( content );

For a better solution, start with the working example found in the Swing tutorial on How to Use Text Areas and then modify the code. This way you will start with a better structured program that follows Swing standards.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!