私は独自の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ルックアンドフィールでは、白い背景が醜いと見えることです。だから私は背景を透明にする可能性を探します。
解決策はありますか?
あなたはそれを作成していませんでした。この投稿からコードを入手しました:http://stackoverflow.com/questions/997942/selecting-text-from-a-jlabel – Michael
非常に役立つ投稿 –