Results 1 to 4 of 4
- 08-29-2009, 10:07 PM #1
Member
- Join Date
- Aug 2009
- Posts
- 2
- Rep Power
- 0
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();
}
}
- 08-29-2009, 10:58 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
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.
- 08-29-2009, 11:16 PM #3
Member
- Join Date
- Aug 2009
- Posts
- 2
- Rep Power
- 0
How can I get the linenumber in a html content textpane ?
- 08-31-2009, 02:38 AM #4
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
It might help if you have some valid HTML in the text pane:
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.Java Code:panel.setContentType("text/html"); panel.setText("<html>1<br>2<br>3<br></html>");
And learn to use the "Code Tags" when you post source code so the code is readable.
Similar Threads
-
Content type for MS files "content/unknown" with URLConnection
By serjant in forum NetworkingReplies: 2Last Post: 05-30-2009, 10:42 AM -
LineNumber.java - beta testers needed
By angryboy in forum New To JavaReplies: 16Last Post: 01-24-2009, 10:54 AM -
Unsupported Content-Type: text/html Supported ones are: [text/xml]
By luislopezco in forum Advanced JavaReplies: 0Last Post: 05-26-2008, 04:26 PM -
how to show a html document on JTextPane
By mary in forum Advanced JavaReplies: 2Last Post: 08-02-2007, 01:40 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks