0

I am creating a program that display text using JTextArea and setLineWrap and then i want just three line display, but i don't know how set line limit.

I tried to used getColumn from TextArea, but that's not work. that's just created new line forever

1

I wanted this:

2

But my result is this:

3

class FrameMaker extends JTextArea{
        FrameMaker() {
            JFrame frame = new JFrame();
            JLabel label = new JLabel();
            JPanel panel = new JPanel();
            JTextArea area = new JTextArea(3, 10);
            Dimension dms = new Dimension(500, 200);
            int num = 0;
            Font font = new Font("궁서", 1, 12);

            frame.setPreferredSize(dms);
            frame.pack();
            frame.add(panel);
            frame.setVisible(true);

            panel.add(area);
            area.setLineWrap(true);

            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            int cnt = 1;  
            while(true) {
                if(cnt == 10)
                    cnt = 1;

                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                TextTester.Text.append(cnt);
                area.setText(TextTester.Text.toString());
                cnt++;
            }
        }
slavoo
  • 5,798
  • 64
  • 37
  • 39
앙기모
  • 1
  • 3
  • It's duplicate question. see [here](https://stackoverflow.com/questions/12160060/how-to-limit-number-of-lines-in-jtextarea) – Adir Dayan Mar 28 '19 at 09:13
  • 1
    Possible duplicate of [How to Limit number of lines in JTextArea?](https://stackoverflow.com/questions/12160060/how-to-limit-number-of-lines-in-jtextarea) – Ivan Kukic Mar 28 '19 at 10:14

0 Answers0