2017-03-16 44 views

回答

2

有没有办法做到这一点,不涉及2周独立的JLabel?

您可以在标签中使用HTML:

firstJLabel.setText("<html><font color=\"red\">Die 1: </font>" + die1 + "</html>"); 

或者你可以使用一个JTextPane,使它看起来像一个标签。它支持属性:

JTextPane textPane = new JTextPane(); 
textPane.setBorder(null); 
textPane.setOpaque(false); 

SimpleAttributeSet green = new SimpleAttributeSet(); 
StyleConstants.setForeground(green, Color.GREEN); 

// Add some text 

try 
{ 
    StyledDocument doc = textPane.getStyledDocument(); 
    doc.insertString(0, die1, null); 
    doc.insertString(0, "Die 1: ", green); 
} 
catch(Exception) {}