Swing滚动文本区域使用绝对定位时不显示文本区域


import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class absolute extends JFrame
{
    public absolute()
    {
        JButton b=new JButton("按钮");
        JTextArea txt=new JTextArea(20,40);

        txt.setBounds(50,60,200,200);
        b.setBounds(100,500,60,30);
        b.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                txt.append("absolute"+"\n");
            }
        });
        setLayout(null);
        add(b);
        add(new JScrollPane(txt));
       // add(txt);
        setTitle("绝对定位");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(800,600);
        setVisible(true);
    }
    public static void main(String[] args)
    {
        SwingUtilities.invokeLater(new Runnable()
        {
            public void run()
            {
                new absolute();
            }
        });
    }
}

当使用滚动文本区域时:

img


不使用滚动文本区域:

img