JTextPane displaying line numbers

Hi,
I have a JTextPane that displays a certain text; I want to add to the left side of it a "sidebar" that displays a number for each line i.e.
1 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
30 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
60 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
90 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
The sidebar i mentioned is that with the numbers (1,30,60...). I want it to have a different color and when i copy the text i want to take only the AAAAA part and not the numbers.
Is there a JComponent i can add to the JTextPane or a method to highlight and make this "side text " non editable?
Thanks in advance for your help
Best Regards
Mubiol

Try this
best regards
Stas
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.rtf.*;
class Test extends JFrame
public Test()
super("Test");
JEditorPane edit = new JEditorPane();
edit.setEditorKit(new MyRTFEditorKit());
edit.setEditable(true);
JScrollPane scroll=new JScrollPane(edit);
getContentPane().add(scroll);
setSize(300,300);
setVisible(true);
public static void main(String a[])
new Test();
class MyRTFEditorKit extends RTFEditorKit
public ViewFactory getViewFactory()
return new MyRTFViewFactory();
class MyRTFViewFactory implements ViewFactory
public View create(Element elem)
String kind = elem.getName();
if (kind != null)
if (kind.equals(AbstractDocument.ContentElementName)) {
return new LabelView(elem);
} else if (kind.equals(AbstractDocument.ParagraphElementName)) {
// return new ParagraphView(elem);
return new MyParagraphView(elem);
} else if (kind.equals(AbstractDocument.SectionElementName)) {
// return new BoxView(elem, View.Y_AXIS);
return new MySectionView(elem, View.Y_AXIS);
} else if (kind.equals(StyleConstants.ComponentElementName)) {
return new ComponentView(elem);
} else if (kind.equals(StyleConstants.IconElementName)) {
return new IconView(elem);
// default to text display
return new LabelView(elem);
class MySectionView extends BoxView {
public MySectionView(Element e, int axis)
super(e,axis);
public void paintChild(Graphics g,Rectangle r,int n) {
if (n>0) {
MyParagraphView child=(MyParagraphView)this.getView(n-1);
int shift=child.shift+child.childCount;
MyParagraphView current=(MyParagraphView)this.getView(n);
current.shift=shift;
super.paintChild(g,r,n);
class MyParagraphView extends javax.swing.text.ParagraphView
public int childCount;
public int shift=0;
public MyParagraphView(Element e)
super(e);
short top=0;
short left=20;
short bottom=0;
short right=0;
this.setInsets(top,left,bottom,right);
public void paint(Graphics g, Shape a)
childCount=this.getViewCount();
super.paint (g,a);
int rowCountInThisParagraph=this.getViewCount(); //<----- YOU HAVE REAL ROW COUNT FOR ONE PARAGRAPH}
System.err.println(rowCountInThisParagraph);
public void paintChild(Graphics g,Rectangle r,int n) {
super.paintChild(g,r,n);
g.drawString(Integer.toString(shift+n+1),r.x-20,r.y+r.height-3);

Similar Messages

  • Displaying line numbers in oracle Sql developer

    hi guys, can someone tell me how to display line numbers in oracle sql developer Version 2.1.1.64?.

    I absolutely didn't know where it was, so I had to look for it, and it appears easy to find.
    Hit Tools
    Hit Preferences
    Expand Code Editor
    Navigate to line gutter
    Now click 'Show line numbers'
    And, oh yes, there is a separate sql developer forum. Please keep sql developer issues in that forum.
    Sybrand Bakker
    Senior Oracle DBA

  • How do I display line numbers? I am using the International Digital Publishing Forum EPUB Validator and the error messages refer to line numbers. Thanks, Earl

    The validator gives me error messages messages that refer to line numbers and positions - very unhelpful. I need to be able to display the line numbers in the reader to find the places where the errors are. Can anybody point me in the right direction? MUch appreciated. Earl

    Adobe Reader can't display epub files. Adobe Reader can't display line numbers.

  • How do I display line numbers in a adobe reader pdf file

    Hello,
    I have a PDF file containing c++ code opened in adobe reader. How do I display line numbers in the file?
    Thanks

    You mean, by adding non existing numbers in front of each line, and using only the free Reader? No way.

  • Displaying line numbers in JTextPane?

    Hi I have attached a JTextPane to an InternalFrame. What i wanted to do is i have to display line number on the left side of the textpane and that should be not editable(only Line number) and when we move to the next line the cursor has to be placed right next to the line number. How this can be done?

    You can try this one http://www.developer.com/java/other/article.php/3318421/Add-Line-Numbering-in-the-JEditorPane.htm
    Or this http://java-sl.com/bullets_numberings.html (bullets/numbering based)
    Or this http://tips4java.wordpress.com/2009/05/23/text-component-line-number/

  • Displaying Line Numbers

    When viewing database packages/procedures/functions in Forms Builder, is there any way to turn on line numbers?

    Richard,
    not as far as I am aware of.
    Frank

  • How to print line numbers in NWDS for Java?

    Hi everyone,
    does someone know how to print out program code with line numbers from the Netweaver Developer Studio for Java? This is inevitable for code reviews.
    In Eclipse 3.4 this issue is solved. Is there possibly such a patch for NWDS as well?
    Thanks,
    Maria

    Hi Pascal,
    thanks for the quick reply. The setting you mention displays line numbers on the screen alright, but printing out does not work.
    We use: SAP NetWeaver Developer Studio for SAP NetWeaver 7.1 SP06 PAT0000, Build id: 200807051938.
    I guess it just does not work, because it was fixed only for Eclipse 3.4, and the above NWDS version bases on Eclipse 3.3.
    What do you recommend for code inspections - copy/paste into PSPad or do you know a more comfortable practice?
    Greetings
    Maria

  • Listing with line numbers

    how do I get a listing with line numbers to check compile errors with?

    how do I get a listing with line numbers to check compile errors with? What listing from where using what?
    AFAIK javac and jikes compilers give you the line numbers. What compiler are you using?
    Or do you mean how to display line numbers with this or that editor? If it isn't obvious I'd suggest getting a proper editor (as others have suggested)!
    BTW: eEdit = jEdit?

  • Printing from Xcode: Line Numbers ?

    How can I print source from Xcode with line numbers ?

    Also not a direct solution but opening your files in Text Wrangler (free version of BBEdit) will allow you to add line numbers that will print out. If you use TextMate I THINK it behaves the same as Xcode and gutter displays line numbers but doesn't print them. TextMate is so extensible there is probably a way to make it print them as well but I'm not that familiar.
    =Tod
    PS I am speaking of Xcode < v3 here. I've only dabbled in v3 so I can't say what may have been added.

  • What is the proper way to record line numbers in Master/Detail records?

    Guys and Gals,
    Been thinking about this for awhile, but thought it best to ask the people who really know what they are doing.
    What is the proper way to record & show line numbers in a Master / Detail record set?
    For example, take Master/Detail relationship Orders and OrderItems. Orders has a column Document_Number and OrderItems has Document_Number, Line_Number. Line_Number should contain the row number 1,2,3,4 ... etc. for each row in a document.
    Should I ...
    <ol><li>Add a sequence and a trigger in the database? The FusionOrderDemo does this, but then the sequence never "resets" and I've got row numbers that keep incrementing. So one document has rows 4,5,6 and the next document has 7,8,9 when they should both have 1,2,3.</li>
    <li>Programmatically take care of the row numbers? This seems like I'm asking for trouble. Anytime an insert or delete operation gets done, I'll have to iterate through rows and re-assign row numbers.</li>
    <li>Is there a way to assign row numbers in a table iterator (or data collection?) to an entity?</li></ol>
    Any suggestions would be appreciated. It's looking like #2 is my only option, but if anyone knows different I'd love the input.
    Will

    Thank you both guys.
    As John said, I believe I'm looking for a gap-free sequence per master record.
    The line number of the OrderItems table is the second half of the primary key. The first half of the primary key (DocumentNumber) is the foreign key to the Orders table.
    Think of it like line items on an order or invoice. For example, if you were talking to someone on the phone concerning an invoice, you might say, "The pricing for line item #3 is incorrect." In this case, it's good to have a common reference. Or imagine a Microsoft Excel spreadsheet with no row numbers displayed! You'd never get anywhere if you had to explain something over the phone.
    If this is tricky to perform, I take it using a sequence and trigger such as the Fusion Order Demo is the best way to approach the challenge for simplicity's sake?
    Will

  • How to print continue Line Numbers  in PLD  Differen repetitve areas.

    Hi,
    We need to print line numbers continues in different Repetitive areas.
    Ex. Repetitve Area 0 we have item Discriptions
          Repetitve Area  Footer1 we created sotvalue() here it will display servicetaxes
          Repetitve Area Footer1 we created one text roundoff
    we need output like
    Ex:1. Dell        **Repetitve Area 0****           
          2.Mouse     **Repetitve Area 0****           
          3.Laptop      **Repetitve Area 0****             
          4.servicetax   **Repetitve Area Footer1****           
          5.cess             **Repetitve Area Footer1****           
          6.Hcess             **Repetitve Area Footer1****           
          7.Roundoff           **Repetitve Area Footer1****    as a text field       
      for above all we need to print Line numbers sequence how we can print sequence numbers for differen  areas.if i  assigned Linenum( ) in Repetitve Area 0 it will display one for Repetitve Area 0 only.and i applied Gouplinenum also it's not printing. please guide me how to print this.
    regds,
    sampath kumar devunuri.

    Hi,clint pow.
    Please we did what you said but we are not retreiving data.please tell me how we can get serieal numbers for different repetitve areas.
    regds,
    sampath.

  • Displaying row numbers in tables

    Is there a way to get JTable to display row numbers on the left-most side of the table? Are there any functions in JTable that will allow you to do this?
    I am thinking that to do this, I will probably need to add a column to my table model and make the first column and uneditable JLabel that shows the row number.
    Thanks for any help.
    Mike Ryan

    Ok , the class i am pulling this code from is 500+ lines of code, so I will try to pull out only the important pieces.
    private DefaultTableModel theNorthernModel;
    private JTable theNorthernTable;
    private DefaultTableCellRenderer[] theRenderer;
    private JScrollPane theNorthernPane;
    private Object[] rowTitles = {"1", "2", "3",  "4", "5",  "6", "7"};//
    private Object[] colTitles  = {"one","two","three","four","five","six"};
         theNorthernModel = new DefaultTableModel(rowTitles.length,colTitles.length);
              theNorthernTable = new JTable(theNorthernModel);
              theNorthernTable.setCellSelectionEnabled(false);
              theNorthernTable.setEnabled(false);
              theNorthernTable.getTableHeader().setReorderingAllowed(false);
              theNorthernPane  = new JScrollPane(theNorthernTable);
              theNorthernPane.setPreferredSize(new Dimension(600, 150));
    //this is the stuff you want          
    ListModel listModel = new AbstractListModel() {
                 public int getSize() {
                         return rowTitles.length;
                public Object getElementAt(int index) {
                     return rowTitles[index];
            JList rowHeader1 = new JList(listModel);
            rowHeader1.setBackground(theNorthernPane.getBackground());
            rowHeader1.setFixedCellWidth(140);
            theNorthernPane.setViewportView(theNorthernTable);
            theNorthernPane.setRowHeaderView(rowHeader1);
            rowHeader1.setCellRenderer(new RowHeaderRenderer(theNorthernTable));
    theRenderer = new DefaultTableCellRenderer[6];
              for(int i = 0; i< 6; i++) {
                   theRenderer[i] = new DefaultTableCellRenderer();     
    theColumnModel = (DefaultTableColumnModel)theNorthernTable.getColumnModel();
    * RowHeaderRenderer renders the panel's rows
    class RowHeaderRenderer extends JLabel implements ListCellRenderer {
         * Constructor creates all cells the same
         * To change look for individual cells put code in
         * getListCellRendererComponent method
        RowHeaderRenderer(JTable table) {
            JTableHeader header = table.getTableHeader();
            setOpaque(true);
            setBorder(UIManager.getBorder("TableHeader.cellBorder"));
            setHorizontalAlignment(CENTER);
            setForeground(header.getForeground());
            setBackground(header.getBackground());
            setFont(header.getFont());
         * Returns the JLabel after setting the text of the cell
        public Component getListCellRendererComponent( JList list,
        Object value, int index, boolean isSelected, boolean cellHasFocus) {
            setText((value == null) ? "" : value.toString());
            return this;
    }

  • Line numbers related to order number

    hi,
    the requirement is , i have two parameters order number and line number.
    i want to display the line numbers related to that particular order number while
    submitting the request from srs window.
    so first i created table value set for order num.
    and for line number value set i mentioned oe_order_lines_all ool,
    oe_order_lines_all ool in table name field and ool.line number in column field
    and in where/order by field i had mentioned like
    where ool.header_id=ooh.header_id
    and ooh.order_number=:$FLEX$.order_num_value_set.
    value set is created but while submitting the request by clicking the line number
    field it is giving error.
    can u plz give any solution.

    .. or dense_rank() ? :
    SELECT line_id,
              line_number
           || '.'
           || DENSE_RANK () OVER (PARTITION BY header_id ORDER BY header_id)
                                                                      line_number
      FROM oe_order_lines_all
    WHERE header_id = 6250

  • Matrix - Help with setting 1st column for line numbers

    Hi,
    I have created a matrix on a custom form and would like to add line numbers to the # column line that of the quotation screen.
    The matrix itself is populated correct from the Query and LoadFromDataSource, and all the fields and columns are filled in correctly, the only column I am having trouble with is the 1st one for line numbers. My code for adding the line numbers is
    SBO_Application.MessageBox("Matrix Count: " & tMatrix.RowCount)
    For i = 1 To tMatrix.RowCount
          oEditText = tColumns.Item("#").Cells.Item(i).Specific
          oEditText.Value = i
    Next
    For the example I am using I get the message box appear:
    Matrix Count: 26
    So I know I should have the line number go from 1 to 26, however I only get 1 to 9 displayed, all the remaining lines are blank.
    Any ideas on why it stops at 9 or what I should do to correctly set the line numbers in the Number column like that of the system Quotation/Sales orders forms.
    Your help is much appreciated
    Matthew

    Hi,
    I tried changing it to the following as you suggested:
    SBO_Application.MessageBox("Matrix Count: " & tMatrix.VisualRowCount)
    For i = 1 To tMatrix.VisualRowCount
        oEditText = tColumns.Item("#").Cells.Item(i).Specific
        oEditText.Value = i
    Next
    The message box still displays 26, however my lines still only go up to number 9.
    Thanks for the quick response.

  • Showing Line Numbers?

    Hi,
    I write news articles for peer review, and one of the main features that I need to display in my drafts are the line numbers for every line. I've tried to search around the pages help as well as these forums, but I'm not finding a solution as to how to display the line numbers in the document as well as on the printed page. Any help? Thanks...
    -Owen

    Hi OwenStratospherical,
    Welcome to Numbers discussions.
    There isn't any built-in way to have line numbers. One possible suggestion, not elegant, is to create a Text Box to the left of the page then using the number keypad enter line numbers in that Text Box. As I said it isn't elegant but, it does work for me when I need it.
    Yes line numbering would be a nice feature for sure.
    The folks on these forums, discussion boards, are end users as yourself not Apple employees. Accept my suggestion for you to please at the top of your screen to the right of the blue Apple click "Pages" > "Provide Pages Feedback". This makes your request known to the Pages team directly. I've sent many as well.
    Let's hope that the next version of Pages (iWork) will incorporate many of the requested enhancements.
    Thank you in advance for doing that.
    Sincerely,
    RicD

Maybe you are looking for

  • How to restrict mounting of files using java

    Is there any way by which we can use java to restrict the OS from mounting files? The usecase is i want to provide a basic level of security so that a normal user(not an expert hacker) can't access the files of my memory card. The java utility will a

  • Iweb 06 firefox not seeing some images

    i am working with iweb 06 and when i put my website on my .mac people running firefox cant see some of the images on the page. I took the site down for now but hear is the link to the page that is up with is one having the trouble. http://www.eclipse

  • Oracle JSP & Tomcat

    Can anyone tell me where I can find Oracle JSP 1.1, mentioned in "Oracle 8i, Java Component Programming with EJB, CORBA and JSP" book? The Oracle JSP release available on Technet is 1.0. Oracle JSP 1.1 is, according to book, prerequisite for an insta

  • Run external programs using runtime class

    Okay, I'm experiencing a really annoying problem with java.lang.runtime I'm building a GUI that needs to run some external programs, via a button say. These generally produce a text file or something, so I don't need to stream the output or anything

  • How can i turn off FMip from a PC

    Hi! I have send my sons IPAD in for service an forgot too turn off FMip. I have tryed to logon icloud.com but I can't find how too turn this func. off?