Unable to make the JTextArea scrollable..!

前端 未结 3 1696
再見小時候
再見小時候 2021-01-24 15:32

Here is my code:

final JTextArea textArea = new JTextArea();
textArea.setFont(new Font(\"MS UI Gothic\", Font.PLAIN, 13));
textArea.setLineWrap(true);
textArea.s         


        
3条回答
  •  暖寄归人
    2021-01-24 16:14

    I don't think you need to do contentPane.add(textArea);. It is this line that is causing the problem. Comment out this and your code should work fine.

    See this answer, it might help you.

    The following code runs fine at my place :

    final JTextArea textArea = new JTextArea();
            textArea.setFont(new Font("MS UI Gothic", Font.PLAIN, 13));
            textArea.setLineWrap(true);
            textArea.setBounds(77, 310, 474, 136);
    
            JScrollPane sbrText = new JScrollPane(textArea);
            sbrText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
            frame.getContentPane().add(sbrText);//contentPane.add(sbrText);
            frame.setVisible(true);
    

    If your code is not running fine then you must have some other error probably related to your contentpane.

提交回复
热议问题