bbrodt / jsyntaxpane

Automatically exported from code.google.com/p/jsyntaxpane
0 stars 1 forks source link

kit.setProperty does not (always) work #168

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.// Initialize the syntax coloring kit
  DefaultSyntaxKit.initKit();

  // Create the editor pane
  editarea = new JEditorPane();
  content.add(new JScrollPane(editarea), BorderLayout.CENTER);
  editarea.setContentType("text/sql");
  editarea.getDocument().addDocumentListener(this);

  // Configure syntax coloring
  SqlSyntaxKit kit = (SqlSyntaxKit)editarea.getEditorKit();
  kit.setProperty("Style.NUMBER", "0x8f0000, 0");
  kit.setProperty("Style.STRING", "0x008f8f, 0");
2.
When writing into the editarea, or if the text of the area is set by
  editarea.setText("some text");
the strings and numbers still appear with the default color.
3.
If the editarea text is set reading a file:
  editarea.read(new FileReader(file), null);
Then the strings and numbers do appear with the configured color.

What is the expected output? What do you see instead?
Allways have strings and numbers with the configured color.

What version of the product are you using? On what operating system?
jsyntaxpane-0.9.5-b29.jar on Windows 7, jdk1.6.0_22

Please provide any additional information below.
The editarea is included in a JInternalFrame.
After setting or reading new text I have to redo:
  editarea.getDocument().addDocumentListener(this);
in order to track text changes.

Original issue reported on code.google.com by bertran...@gmail.com on 30 Dec 2010 at 4:12

Attachments:

GoogleCodeExporter commented 8 years ago
I think you already have a good workaround :-)

You should generally set any of the properties BEFORE attaching the kit to the 
editorpane (using setContentType).  In you example, move the setProperty calls 
above the setContentType.  This will ensure all latest changed the properties 
are used.  Not all properties will support being changed dynamically after the 
kit is attached to the editor.

I think after you read a file, the document of the editor is destroyed and a 
new one is created, so you need to add the document listeners again.  This is 
not jsyntaxpane issue, but a Java Swing issue.

Original comment by ayman.al...@gmail.com on 26 Feb 2011 at 5:59

GoogleCodeExporter commented 8 years ago
The issue is that I get the instance of the kit by the "preferred method":

             editarea.setContentType("text/sql");

             // Configure syntax coloring
             SqlSyntaxKit kit = (SqlSyntaxKit)editarea.getEditorKit();
             ...

How can I get it before "setContentType"? You said somewhere that a 
second method is to get the class name of the kit by:

             JEditorPane.getEditorKitClassNameForContentType("text/sql");

But I don't figure out how this is used; could you provide an example of 
how to code this method to get the kit instance?

Original comment by bertran...@gmail.com on 6 Mar 2011 at 5:15