// Purpose. JSplitPane, JTextArea, and document model demo import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class JSplitPaneDemo { public static void main( String[] args ) { JFrame frame = new JFrame( "JSplitPane demo" ); frame.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } } ); String str = readFile( "JSplitPaneDemo.txt" ); JTextArea first = new JTextArea( str, 8, 40 ); JTextArea second = new JTextArea( 8, 20 ); JTextArea third = new JTextArea( 8, 20 ); // Register first's "model" with "views" second and third second.setDocument( first.getDocument() ); third.setDocument( first.getDocument() ); first.setLineWrap( true ); first.setWrapStyleWord( true ); second.setLineWrap( true ); second.setWrapStyleWord( true ); third.setLineWrap( true ); third.setWrapStyleWord( true ); JSplitPane leftAndRight = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(second), new JScrollPane(third) ); JSplitPane topAndBottom = new JSplitPane( JSplitPane.VERTICAL_SPLIT, new JScrollPane(first), leftAndRight ); frame.getContentPane().add( topAndBottom, BorderLayout.CENTER ); frame.pack(); frame.setVisible( true ); } private static String readFile( String fn ) { StringBuffer sb = new StringBuffer(); try { BufferedReader br = new BufferedReader( new FileReader( fn ) ); String s; while ((s = br.readLine()) != null) if (s.equals( "" )) sb.append( "\n\n" ); else sb.append( s + " " ); br.close(); } catch( Exception ex ) { System.out.println( ex ); } return sb.toString(); } }