JOptionPane.showMessageDialog truncates JTextArea message

后端 未结 4 1272
猫巷女王i
猫巷女王i 2021-01-15 04:20

My Java GUI application needs to quickly show some text to the end-user, so the JOptionPane utility methods seem like a good fit. Moreover, the text must be se

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-15 04:32

    import java.awt.*;
    import javax.swing.*;
    
    public class TextAreaPreferredHeight2
    {
     public static void main(String[] args)
     {
      String text = "one two three four five six seven eight nine ten ";
      JTextArea textArea = new JTextArea(text);
      textArea.setColumns(30);
      textArea.setLineWrap( true );
      textArea.setWrapStyleWord( true );
      textArea.append(text);
      textArea.append(text);
      textArea.append(text);
      textArea.append(text);
      textArea.append(text);
      textArea.setSize(textArea.getPreferredSize().width, 1);
      JOptionPane.showMessageDialog(
       null, textArea, "Not Truncated!", JOptionPane.WARNING_MESSAGE);
     }
    }
    

提交回复
热议问题