views:

116

answers:

2

I'm looking for a way to disable HTML parsing of the addItem() method in JComboBox().

JComboBox jHighlight = new JComboBox();
for (int i = 0; i < tl.size(); i++) {
     //getTagname() returns a string like "br", "a", "body" or "html"
     jHighlight.addItem("<" + tl.get(i).getTagname() + ">");
}

The output in the JComboBox will look like this:

<a>
<br>
<body>
         //notice the blank space where <html> should be
<link>
<meta>

So the problem is that the html-tag is parsed since I add a < sign in front of it, how can I work around this? I've tried to use "\u003C" instead, but it still parses as html and the tag doesn't show up in the list.

A: 

Use “&lt;” instead of “<” and (maybe) wrap it in HTML. ;)

<html>&lt;html></html>
Bombe
+1  A: 

I believe either of the following two statements will do it:

highlight.putClientProperty("html.disable", true);  

highlight.putClientProperty(
    javax.swing.plaf.basic.BasicHTML.propertyKey, null
);

If you have somewhere central you create and configure components, you might want to consider setting it for all. The design of HTML text in component support is not good.

Tom Hawtin - tackline