开发者

trying to create a scroll pane for text area

开发者 https://www.devze.com 2023-04-11 22:41 出处:网络
I\'m trying to create a scroll pane for my jtextarea. Below is my code snippet. I wonder why it didn\'t work. Can someone provide me some insights? Thanks.

I'm trying to create a scroll pane for my jtextarea. Below is my code snippet. I wonder why it didn't work. Can someone provide me some insights? Thanks.

    JTextArea textArea = new JTextArea(st);
    textArea.setBounds(145, 51, 327, 53);
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textArea.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    //ScrollPane Code
    JScrollPane areaScrollPane = new JScrollPane(textArea);
    areaScrollPane.setHorizontalScrollBarPolicy(
                    JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    areaScrollPane.setPreferredSize(new Dimension(250, 250));
    panel.add(textArea);

Did I miss something? There is no scrollpane appear in my textarea开发者_StackOverflow.


You're adding textArea to panel instead of areaScrollPane. Try

panel.add(areaScrollPane);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号