복사가 가능하다는 장점이있는 자체 Label 클래스를 만들었습니다.JTextPane 배경을 투명하게 만들기
public class CopyableLabel extends JTextPane {
private static final long serialVersionUID = -1;
private static final Font DEFAULT_FONT;
static
{
Font font = UIManager.getFont("Label.font");
DEFAULT_FONT = (font != null) ? font: new Font("Tahoma", Font.PLAIN, 11);
}
public CopyableLabel() {
construct();
}
private void construct()
{
setContentType("text/html");
setEditable(false);
setOpaque(false);
setBackground(null);
setBorder(null);
putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
setFont(DEFAULT_FONT);
}
public CopyableLabel(String text)
{
super();
construct();
setText(text);
}
public void setFont(Font font)
{
super.setFont(font);
setMaximumSize(new Dimension(Short.MAX_VALUE,font.getSize()+4));
}
public CopyableLabel(String title, int align)
{
super();
construct();
setText(title);
StyledDocument doc = getStyledDocument();
SimpleAttributeSet center = new SimpleAttributeSet();
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
switch(align)
{
case JLabel.LEFT:
StyleConstants.setAlignment(center, StyleConstants.ALIGN_LEFT);
break;
case JLabel.RIGHT:
StyleConstants.setAlignment(center, StyleConstants.ALIGN_RIGHT);
break;
}
doc.setParagraphAttributes(0, doc.getLength(), center, false);
}
문제는 Nimbus Look and Feel에서 흰색 배경이보기 흉한 것입니다. 그래서 나는 배경을 투명하게 할 수있는 가능성을 찾는다.
해결책이 있습니까?
당신이 그것을 만들지 않았다, 당신은이 게시물에서 코드를 가지고 : http://stackoverflow.com/questions/997942/selecting-text-from-a-jlabel – Michael
매우 유용한 게시물 –