1 7 package org.enhydra.base.tool; 8 9 import javax.swing.JPanel ; 10 11 import javax.swing.JTextArea ; 12 import java.awt.BorderLayout ; 13 import java.io.IOException ; 14 import java.io.Writer ; 15 import javax.swing.JScrollPane ; 16 22 public class OutputPanel extends JPanel { 23 24 private JScrollPane jScrollPane = null; 25 private JTextArea output = null; 26 29 public OutputPanel() { 30 super(); 31 initialize(); 32 } 33 38 private void initialize() { 39 this.setLayout(new BorderLayout ()); 40 this.setPreferredSize(new java.awt.Dimension (300,150)); 41 this.setSize(300, 150); 42 this.add(getJScrollPane(), java.awt.BorderLayout.CENTER); 43 } 44 45 public void setWriter(Writer writer){ 46 try { 47 output.write(writer); 48 } catch (IOException ex){ 49 System.out.println("Unable to set writer!"); 50 } 51 } 52 53 public void setText(String text){ 54 output.setText(text); 55 } 56 57 public void appendText(String text){ 58 output.append(text); 59 } 60 61 public void appendTextLine(String text){ 62 output.append(text+"\n"); 63 jScrollPane.getVerticalScrollBar().setValue(output.getHeight()); 64 } 65 66 public void clearText(){ 67 output.setText(""); 68 } 69 70 75 private JScrollPane getJScrollPane() { 76 if (jScrollPane == null) { 77 jScrollPane = new JScrollPane (); 78 jScrollPane.setViewportView(getOutput()); 79 } 80 return jScrollPane; 81 } 82 87 private JTextArea getOutput() { 88 if (output == null) { 89 output = new JTextArea (); 90 output.setName("output"); 91 output.setEditable(false); 92 } 93 return output; 94 } 95 } 96 | Popular Tags |