import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; public class JTextAreaDemo { JFrame frame=new JFrame("JTextArea Demo"); JTextArea ta1,ta2; JButton copy,clear; public static void main(String args[]){ JTextAreaDemo tad=new JTextAreaDemo(); tad.go(); } void go(){ ta1=new JTextArea(3,15); ta1.setSelectedTextColor(Color.red); ta2=new JTextArea(7,20); ta2.setEditable(false); JScrollPane jsp1=new JScrollPane(ta1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); JScrollPane jsp2=new JScrollPane(ta2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); copy=new JButton("Copy"); copy.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if(ta1.getSelectedText()!=null) ta2.append(ta1.getSelectedText()+"/n"); else ta2.append("/n"+ta1.getText()+"/n"); } }); clear=new JButton("Clear"); clear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ta2.setText(""); } }); JPanel panel=new JPanel(); panel.add(jsp1); panel.add(copy); Border etched=BorderFactory.createEtchedBorder(); panel.setBorder(etched); JPanel panel2=new JPanel(); panel2.add(jsp2); panel2.add(clear); panel2.setBorder(etched); Container cp= frame.getContentPane(); cp.add(panel,BorderLayout.CENTER); cp.add(panel2,BorderLayout.SOUTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } }