2014-02-16 43 views
2

我有一個顯示含有像這樣的圖像鏈接一個JEditorPane:JEditorPane中從圖像鏈接刪除邊框

<a href='http://somesite.com/'> 
    <img src='someImage.png' /> 
</a> 

當JEditorPane中顯示此爲HTML,它把圖像帶有藍色邊框我正努力刪除沒有任何運氣。

我希望它看起來像這裏面的JEditorPane中的: 圖像:(http://randomcloud.net/img/prob/valid.png

但這是JEditorPane中如何顯示它: 圖像(http://randomcloud.net/img/prob/jeditorpane.png

這是我曾嘗試到目前爲止,它仍然不起作用

editorPane = new JEditorPane("http://randomcloud.net/ads/index.php?id=1"); 
StyleSheet style = ((HTMLDocument)editorPane.getDocument()).getStyleSheet(); 
style.addRule("a img {text-decoration: none; border: none;}"); 

任何建議或見解?

-Michel

回答

1

HTLEditorKit的ImageView源代碼。正如你可以看到borderSize被設置爲DEFAULT_BORDER(2像素)。你可以在ViewFactory實現中替換ImageView創建,並覆蓋提供所需邊框的方法(0,據我所知)。

protected void setPropertiesFromAttributes() { 
    StyleSheet sheet = getStyleSheet(); 
    this.attr = sheet.getViewAttributes(this); 

    // Gutters 
    borderSize = (short)getIntAttr(HTML.Attribute.BORDER, isLink() ? 
            DEFAULT_BORDER : 0); 

    leftInset = rightInset = (short)(getIntAttr(HTML.Attribute.HSPACE, 
               0) + borderSize); 
    topInset = bottomInset = (short)(getIntAttr(HTML.Attribute.VSPACE, 
               0) + borderSize); 

    borderColor = ((StyledDocument)getDocument()).getForeground 
        (getAttributes()); 

    AttributeSet attr = getElement().getAttributes(); 

    // Alignment. 
    // PENDING: This needs to be changed to support the CSS versions 
    // when conversion from ALIGN to VERTICAL_ALIGN is complete. 
    Object alignment = attr.getAttribute(HTML.Attribute.ALIGN); 

    vAlign = 1.0f; 
    if (alignment != null) { 
     alignment = alignment.toString(); 
     if ("top".equals(alignment)) { 
      vAlign = 0f; 
     } 
     else if ("middle".equals(alignment)) { 
      vAlign = .5f; 
     } 
    } 

    AttributeSet anchorAttr = (AttributeSet)attr.getAttribute(HTML.Tag.A); 
    if (anchorAttr != null && anchorAttr.isDefined 
     (HTML.Attribute.HREF)) { 
     synchronized(this) { 
      state |= LINK_FLAG; 
     } 
    } 
    else { 
     synchronized(this) { 
      state = (state | LINK_FLAG)^LINK_FLAG; 
     } 
    } 
} 

我覺得藍色邊框只是文本的選擇。嘗試取消內容或使用jEditorPaneInstance.getCaret().setSelectionVisible(false);

+0

謝謝!創建我自己的ImageView並使用所描述的方法刪除邊框。 – Alien595

1

@ Alien595:在IMG標籤,你可以添加一個名爲邊境是0

例子中的屬性:

<a href="your_link.html"> 
    <img border="0" src="your_image.png"/> 
</a>