Results 1 to 4 of 4
  1. #1
    mcjava is offline Member
    Join Date
    Aug 2009
    Posts
    2
    Rep Power
    0

    Default LineNumber JTextPane html Content

    Hallo,
    I want to print the line numbers out. My Problem is: When I set the ContentType to ("text/html") of my JTextPane the prog shows the line numbers no more, but the number of the character in the JTextPane. How can I print the linenumber out in a JTextPane with the contenttype ("text/html") ??

    Thanks for your help -> my code :)

    public class minenfeld {
    int counter;
    int fieldcounter = 1;
    JTextPane [] textpanes = new JTextPane[200];
    Document [] d = new Document[200];
    JFrame main = new JFrame();
    JTextPane panel = new JTextPane();
    JPanel writepanel = new JPanel();

    public void windows(){

    main.setSize(800, 600);
    panel.setPreferredSize(new Dimension(600,200));
    panel.addKeyListener(new EnterKeyListener());

    panel.setContentType("text/html");
    writepanel.add(panel);
    main.add(writepanel);
    main.setVisible(true);
    }

    class EnterKeyListener implements KeyListener
    {

    public void keyPressed(KeyEvent e) {
    int key = e.getKeyCode();
    if (key == KeyEvent.VK_ENTER) {

    int caretPosition = panel.getCaretPosition();
    Element root = panel.getDocument().getDefaultRootElement();

    int rub = root.getElementIndex( caretPosition ) + 1;
    System.out.println(rub);
    }
    }
    public void keyReleased(KeyEvent k){}

    public void keyTyped(KeyEvent k){}
    }
    public static void main(String[] args){

    minenfeld test = new minenfeld();
    test.windows();
    }
    }

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Line numbers? Even without setting the content type you are still not displaying the current line numbers.
    Just add, delete some lines and you should see that you are no longer printing the line numbers that you though you were printing.

  3. #3
    mcjava is offline Member
    Join Date
    Aug 2009
    Posts
    2
    Rep Power
    0

    Default

    How can I get the linenumber in a html content textpane ?

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default

    It might help if you have some valid HTML in the text pane:

    Java Code:
    panel.setContentType("text/html");
    panel.setText("<html>1<br>2<br>3<br></html>");
    Personally, I've never had much luck using the text pane with HTML for editing text. It can display some basic HTML. But for styled text I just use attributes in the text pane.

    And learn to use the "Code Tags" when you post source code so the code is readable.

Similar Threads

  1. Replies: 2
    Last Post: 05-30-2009, 10:42 AM
  2. LineNumber.java - beta testers needed
    By angryboy in forum New To Java
    Replies: 16
    Last Post: 01-24-2009, 10:54 AM
  3. Replies: 0
    Last Post: 05-26-2008, 04:26 PM
  4. how to show a html document on JTextPane
    By mary in forum Advanced Java
    Replies: 2
    Last Post: 08-02-2007, 01:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •