为JTextArea添加JScrollPane

2025-02-02 23:52:03
推荐回答(1个)
回答1:

	public static void main(String[] args)
{
JFrame jf = new JFrame();
jf.setSize(200,200);

jf.setLayout(new FlowLayout());
JPanel jp = new JPanel();
jp.setSize(50,50);
jp.setBackground(Color.RED);
jp.setLayout(new FlowLayout());
JTextArea jt= new JTextArea(5,5); 
JScrollPane js = new JScrollPane(jt);

jp.add(js);
jf.add(jp);
jf.setVisible(true);
}

主要是jf.setVisible(true);放到最后。