日期:2014-05-20 浏览次数:20686 次
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
public class Test {
public static void main(String[] args) {
UIManager.put("Label.foreground", Color.BLUE);
JFrame frame = new JFrame("Label");
JLabel label1 = new JLabel("Label One");
JLabel label2 = new JLabel("Label Two");
frame.getContentPane().add(label1);
frame.getContentPane().add(label2, BorderLayout.SOUTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
private JLabel makeLabel(String text){
JLabel label = new JLabel(text);
label.setForeground(Color.BLUE);
return label;
}
JPanel panel = ...;
panel.add(makeLabel("Hello"));
panel.add(makeLabel("Goodbye"));