WEB开发网
开发学院WEB开发Jsp JTextArea中显示LineNumber 阅读

JTextArea中显示LineNumber

 2008-01-05 20:23:52 来源:WEB开发网   
核心提示://package tryLineNumber;import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Point;

//package tryLineNumber;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;


import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
//import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;


/**
  * A class illustrating running line number count on JTextPane. Nothing
is painted on the pane itself,
  * but a separate JPanel handles painting the line numbers.<br>
  *
  * @author Daniel Sj?blom<br>
  * Created on Mar 3, 2004<br>
  * Copyright (c) 2004<br>
  * @version 1.0<br>
  */
public class LineNr extends JPanel
{
     // for this simple experiment, we keep the pane + scrollpane as members.
     //JTextPane pane;
     JTextArea pane;
     JScrollPane scrollPane;


     public LineNr()
     {
         super();
         setMinimumSize(new Dimension(30, 30));
         setPReferredSize(new Dimension(30, 30));
         setMinimumSize(new Dimension(30, 30));
         //pane = new JTextPane() // we need to override paint so that the linenumbers stay in sync
         pane = new JTextArea()
         {
             public void paint(Graphics g)
             {
                 super.paint(g);
                 LineNr.this.repaint();
             }
         };
         scrollPane = new JScrollPane(pane);


Tags:JTextArea 显示 LineNumber

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接