一个带有JTextArea的通用JScrollPane

包括2个文件: MyScrollFrame 和 MyJScrollPane两个java文件 .

//////////////////////////////// 1. MyScrollFrame.java /////////////////////////////

package com.swing.test;

import javax.swing.JFrame;

import javax.swing.JTextArea;
import javax.swing.JTextField;

 

public class MyScrollFrame extends JFrame{
 
 public  static JTextArea jta_info = new JTextArea(10,30);
 
 public  JTextField jtf_port;
 private MyJScrollPane scrollPane;
 
 public MyScrollFrame(){
  scrollPane = new MyJScrollPane("ScrollPane Test");
  this.add(scrollPane);
  
  this.setTitle("test");
  this.setSize(410,380);
  
  this.setDefaultCloseOperation(EXIT_ON_CLOSE);


     setResizable(false);

  this.setVisible(true);
 }
 
 public static void main(String[] args) {
  new MyScrollFrame();
 }

}

 

//////////////////////////////// 1. MyJScrollPane.java /////////////////////////////

package com.swing.test;


import java.awt.Dimension;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.text.StyledDocument;


public class MyJScrollPane extends JScrollPane{
 
 private JTextArea addText;
 private JButton btn;
 private JScrollPane addScrollPane;
 
 //JTextPane textPane = new JTextPane();
 //private StyledDocument document = (StyledDocument) textPane.getDocument();
 
    public MyJScrollPane(String title) {
  addText = new JTextArea();
  addScrollPane = new JScrollPane(addText);
  //btn = new JButton("确认");
  if (title != null  && ( !(title.isEmpty()))) {
   this.setBorder(javax.swing.BorderFactory.createTitledBorder(title));
  }
  this.add(addScrollPane);
  this.setViewportView(addScrollPane);
  this.setPreferredSize(new Dimension(280,190));
 }
    public String getText() {
     return addText.getText();
    }
    public void setText(String text) {
      addText.setText(text);
    }

}

 

 

你可能感兴趣的:(一个带有JTextArea的通用JScrollPane)