下面列出了javax.swing.JLabel#setForeground ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected JLabel createTitleLabel(int preferredWidth) {
JLabel result = new JLabel(getTitle());
result.setHorizontalAlignment(SwingConstants.CENTER);
if (getIcon() != null) {
result.setIcon(getIcon());
result.setIconTextGap(10);
}
result.setBackground(titleBgColor);
result.setForeground(titleForeColor);
result.setOpaque(true);
result.setBorder(titleBorder);
result.validate();
Dimension d = result.getPreferredSize();
result.setPreferredSize(new Dimension(Math.max(d.width, preferredWidth), d.height));
result.setMinimumSize(result.getPreferredSize());
return result;
}
public EndGameMessagePanel(GameViewerInfo game) {
setPreferredSize(new Dimension(450, 350));
setLayout(miglayout);
//
setOpaque(true);
setBorder(BorderFactory.createMatteBorder(8, 8, 8, 8, MagicStyle.getTheme().getColor(Theme.COLOR_TITLE_BACKGROUND)));
//
final JLabel iconLabel = new JLabel(game.getWinningPlayer().getPlayerPanelAvatar());
final Icon winningAvatar = iconLabel.getIcon();
iconLabel.setPreferredSize(new Dimension(winningAvatar.getIconWidth(), winningAvatar.getIconHeight()));
add(iconLabel, "alignx center");
//
final JLabel winnerLabel = new JLabel(MText.get(_S1, game.getWinningPlayer().getName()));
winnerLabel.setFont(FontsAndBorders.FONT3);
winnerLabel.setHorizontalAlignment(SwingConstants.CENTER);
winnerLabel.setForeground(MagicStyle.getTheme().getColor(Theme.COLOR_TEXT_FOREGROUND));
add(winnerLabel, "w 100%");
}
@Override
public Component getListCellRendererComponent(JList<? extends MagicCollection> list, MagicCollection value, int index,boolean isSelected, boolean cellHasFocus) {
if (value != null) {
JLabel l = new JLabel(value.getName());
l.setOpaque(true);
l.setToolTipText(value.getName());
if (isSelected) {
l.setBackground(list.getSelectionBackground());
l.setForeground(list.getSelectionForeground());
} else {
l.setBackground(list.getBackground());
l.setForeground(list.getForeground());
}
l.setIcon(MTGConstants.ICON_COLLECTION);
return l;
}
return new JLabel();
}
@Override
public Component getListCellRendererComponent(JList list,
Object value, int index, boolean isSelected,
boolean hasFocus) {
JLabel label = (JLabel) super.getListCellRendererComponent(
list, value, index, isSelected, hasFocus);
if (this.iconEnable && index == 0) {
label.setIcon(ICON);
} else if (index == 1) {
Font font = label.getFont().deriveFont(10.0f);
label.setFont(font);
label.setForeground(Color.GRAY);
}
return label;
}
public WodHealthTab(FoxSpacecraft spacecraft) {
super(spacecraft, DisplayModule.DISPLAY_WOD);
topPanel1.add(new Box.Filler(new Dimension(14,fonth), new Dimension(1600,fonth), new Dimension(1600,fonth)));
lblFramesDecoded = new JLabel("WOD Payloads Decoded:");
lblFramesDecoded.setFont(new Font("SansSerif", Font.BOLD, (int)(Config.displayModuleFontSize * 14/11)));
lblFramesDecoded.setBorder(new EmptyBorder(5, 2, 5, 5) );
lblFramesDecoded.setForeground(textLblColor);
topPanel1.add(lblFramesDecoded);
lblFramesDecodedValue = new JLabel();
lblFramesDecodedValue.setFont(new Font("SansSerif", Font.BOLD, (int)(Config.displayModuleFontSize * 14/11)));
lblFramesDecodedValue.setBorder(new EmptyBorder(5, 2, 5, 5) );
lblFramesDecodedValue.setForeground(textColor);
topPanel1.add(lblFramesDecodedValue);
lblResetsValue = addReset(topPanel2, "Last WOD:");
lblUptimeValue = addUptime(topPanel2, "");
// topPanel2.add(new Box.Filler(new Dimension(14,fonth), new Dimension(400,fonth), new Dimension(1600,fonth)));
lblSatLatitudeValue = addTopPanelValue(topPanel2, "Footprint Latitude:");
lblSatLongitudeValue = addTopPanelValue(topPanel2, "Longitude:");
}
@Override
public Component getListCellRendererComponent(
final JList<? extends Construction> list, final Construction value,
final int index, final boolean isSelected, final boolean cellHasFocus) {
JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(
list, value, index, isSelected, cellHasFocus);
renderer.setFont(GuiStatics.getFontCubellan());
renderer.setIcon(value.getIcon().getAsIcon());
if (isSelected) {
renderer.setForeground(GuiStatics.COLOR_COOL_SPACE_BLUE);
renderer.setBackground(GuiStatics.COLOR_DEEP_SPACE_PURPLE);
} else {
renderer.setForeground(GuiStatics.COLOR_COOL_SPACE_BLUE_DARK);
renderer.setBackground(GuiStatics.COLOR_DEEP_SPACE_PURPLE_DARK);
}
return renderer;
}
/**
* Creates bug summary component. If obj is a string will create a JLabel
* with that string as it's text and return it. If obj is an annotation will
* return a JLabel with the annotation's toString(). If that annotation is a
* SourceLineAnnotation or has a SourceLineAnnotation connected to it and
* the source file is available will attach a listener to the label.
*/
public Component bugSummaryComponent(String str, BugInstance bug) {
JLabel label = new JLabel();
label.setFont(label.getFont().deriveFont(Driver.getFontSize()));
label.setFont(label.getFont().deriveFont(Font.PLAIN));
label.setForeground(Color.BLACK);
label.setText(str);
SourceLineAnnotation link = bug.getPrimarySourceLineAnnotation();
if (link != null) {
label.addMouseListener(new BugSummaryMouseListener(bug, label, link));
}
return label;
}
private void setup() {
this.setLayout(new MigLayout("ins 0"));
skillLevelLabel = new JLabel("-");
skillLevelLabel.setFont(style.font);
skillLevelLabel.setForeground(style.foregroundColor);
this.setBackground(style.backgroundColor);
skillLevelLabel.addMouseListener(this);
skillImageLabel = new JLabel(
new ImageIcon(getClass().getClassLoader().getResource("resources/logo_" + skill + ".gif")));
skillImageLabel.addMouseListener(this);
add(skillImageLabel, "cell 0 0, ");
add(skillLevelLabel, "cell 1 0,");
}
private JLabel getDialogCaptionLabel() {
final JLabel lbl = new JLabel(getTitle());
lbl.setOpaque(true);
lbl.setBackground(MagicStyle.getTheme().getColor(Theme.COLOR_TITLE_BACKGROUND));
lbl.setForeground(MagicStyle.getTheme().getColor(Theme.COLOR_TITLE_FOREGROUND));
lbl.setFont(FontsAndBorders.FONT1.deriveFont(14f));
lbl.setHorizontalAlignment(SwingConstants.CENTER);
return lbl;
}
private JLabel getPlayerNameLabel() {
final JLabel lbl = new JLabel(profile.getPlayerName());
lbl.setFont(FontsAndBorders.FONT2);
lbl.setForeground(foreColor);
lbl.setVerticalAlignment(SwingConstants.TOP);
return lbl;
}
KeywordPanelA(Keyword keyword) {
setLayout(new MigLayout("insets 0, gap 0, flowy"));
setOpaque(false);
final JLabel nameLabel = new JLabel(keyword.getName());
nameLabel.setForeground(NAME_COLOR);
nameLabel.setFont(FontsAndBorders.FONT2);
add(nameLabel, "w 100%");
final JLabel descriptionLabel = new JLabel();
descriptionLabel.setText(keyword.getDescriptionAsHtml());
descriptionLabel.setForeground(TEXT_COLOR);
add(descriptionLabel, "w 10:100%");
}
private JLabel getDialogCaptionLabel() {
final JLabel lbl = new JLabel(getTitle());
lbl.setOpaque(true);
lbl.setBackground(MagicStyle.getTheme().getColor(Theme.COLOR_TITLE_BACKGROUND));
lbl.setForeground(MagicStyle.getTheme().getColor(Theme.COLOR_TITLE_FOREGROUND));
lbl.setFont(FontsAndBorders.FONT1.deriveFont(14f));
lbl.setHorizontalAlignment(SwingConstants.CENTER);
return lbl;
}
private void initSiteLink(JLabel label, MouseListener mouseListener) {
if (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
return;
}
label.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
label.setForeground(Color.blue);
label.addMouseListener(mouseListener);
}
private void setInterceptHighLight()
{
JLabel label = new JLabel(tabbedpane.getTitleAt(1));
label.setForeground(Color.ORANGE);
tabbedpane.setTabComponentAt(1, label);
tabbedpane.revalidate();
tabbedpane.repaint();
}
public TextDialog(Component parent, String text)
{
super();
JLabel lblText = new JLabel(addLineBreaks(text));
lblText.setFont(FONT);
lblText.setForeground(Color.WHITE);
contentPanel.add(lblText, "gapx 15 0, cell 0 1,alignx center,aligny bottom");
JLabel spacer = new JLabel(" ");
contentPanel.add(spacer, "cell 0 3");
finalize(parent);
}
/**
* Creates the WindowGui
*
* @param icon
* @param head
* @param body
* @param posx
* @param posy
* @param backgroundcolor
* @param headerColor
* @param messageColor
* @return
*/
private static JWindow createWindow(Icon icon, String head, String body, int posx, int posy, Color backgroundcolor,
Color headerColor, Color messageColor) {
final JWindow window = new JWindow();
JPanel windowpanel = new JPanel(new GridBagLayout());
windowpanel.setBackground(backgroundcolor);
AWTUtilities.setWindowShape(window, new RoundRectangle2D.Float(0, 0, WIDTH, HEIGHT, 20, 20));
try
{
AWTUtilities.setWindowOpaque( window, true );
} catch ( UnsupportedOperationException ex ) {
Log.debug( "Unable to make window opaque: " + ex );
}
JLabel text = new JLabel("<HTML>" + body + "</HTML>");
text.setForeground(messageColor);
JLabel header = new JLabel(head);
header.setForeground(headerColor);
header.setFont(new Font(header.getFont().getName(), Font.BOLD, header.getFont().getSize() + 2));
windowpanel.add(new JLabel(icon), new GridBagConstraints(0, 0, 1, 2, 0.0, 0.0, GridBagConstraints.CENTER,
GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
windowpanel.add(header, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
GridBagConstraints.BOTH, new Insets(5, 5, 0, 5), 0, 0));
windowpanel.add(text, new GridBagConstraints(1, 1, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST,
GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 5), 0, 0));
window.add(windowpanel);
window.setSize(WIDTH, HEIGHT);
window.setLocation(posx - (WIDTH + 5), posy + 5);
window.setAlwaysOnTop(true);
return window;
}
public DoneStepPanel() {
setLayout(new GridBagLayout());
setBackground(Color.BLACK);
setOpaque(false);
JLabel label = new JLabel(
Application.getResourceBundle().getString("step.3.doneTitle"));
label.setFont(new Font("Helvetica", Font.BOLD, 64)); // NON-NLS
label.setForeground(Color.WHITE);
add(label, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
GridBagConstraints.CENTER,
GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
}
/**
* Create the frame.
*/
public ReadLogsWindow() {
setTitle("Coder HPMSA - [Read Logs]");
setBounds(100, 100, 660, 550);
setBackground(Color.decode("#066d95"));
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setIconImage(Toolkit.getDefaultToolkit().
getImage(getClass().getResource(LOGOPATH)));
final JScrollPane scrollPane = new JScrollPane();
scrollPane.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
getContentPane().add(scrollPane, BorderLayout.CENTER);
editorPane = new JTextPane();
editorPane.setBackground(new Color(255, 255, 240));
editorPane.setFont(new Font("Verdana", Font.PLAIN, 13));
editorPane.setBorder(new EtchedBorder(EtchedBorder.RAISED, null, null));
editorPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
editorPane.setEditable(false);
scrollPane.setViewportView(editorPane);
final JPanel filesPanel = new JPanel();
filesPanel.setPreferredSize(new Dimension(200, 10));
getContentPane().add(filesPanel, BorderLayout.EAST);
filesPanel.setLayout(new BorderLayout(0, 0));
final JScrollPane listScrollPane = new JScrollPane();
listScrollPane.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
listScrollPane.setViewportView(logFilesList());
filesPanel.add(listScrollPane, BorderLayout.CENTER);
final JPanel titlePanel = new JPanel();
titlePanel.setPreferredSize(new Dimension(10, 40));
titlePanel.setBackground(Color.decode("#066d95"));
titlePanel.setAutoscrolls(true);
getContentPane().add(titlePanel, BorderLayout.NORTH);
titlePanel.setLayout(new BorderLayout(0, 0));
final JLabel lblTitle = new JLabel("SYSTEM LOG RECORDS");
lblTitle.setHorizontalTextPosition(SwingConstants.CENTER);
lblTitle.setHorizontalAlignment(SwingConstants.CENTER);
lblTitle.setAutoscrolls(true);
lblTitle.setFont(new Font("Verdana", Font.BOLD, 25));
lblTitle.setForeground(UIManager.getColor("Button.highlight"));
titlePanel.add(lblTitle, BorderLayout.CENTER);
final StyledDocument doc = editorPane.getStyledDocument();
final SimpleAttributeSet center = new SimpleAttributeSet();
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
doc.setParagraphAttributes(0, doc.getLength(), center, false);
setVisible(true);
}
private void initComponents() {
Dimension windowSize = new Dimension(windowWidth, windowHeight);
setMinimumSize(windowSize);
setMaximumSize(windowSize);
controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 5));
// controlPanel.setBounds(0,5, windowWidth, 30);
closeLabel = new JLabel();
closeLabel.setIcon(IconUtil.getIcon(this, "/image/close.png"));
closeLabel.setHorizontalAlignment(JLabel.CENTER);
// closeLabel.setPreferredSize(new Dimension(30,30));
closeLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
titleLabel = new JLabel();
titleLabel.setText("登录 XyTalk");
titleLabel.setFont(FontUtil.getDefaultFont(16));
downloadLabel = new JLabel();
downloadLabel.setText("下载客户端软件");
downloadLabel.setFont(FontUtil.getDefaultFont(14));
remberPsw = new JCheckBox("记住密码", true);
remberPsw.setFont(FontUtil.getDefaultFont(14));
offlineLogin = new JCheckBox("断网离线登陆", false);
offlineLogin.setFont(FontUtil.getDefaultFont(14));
editPanel = new JPanel();
editPanel.setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 5, true, false));
Dimension textFieldDimension = new Dimension(200, 35);
usernameField = new RCTextField();
usernameField.setPlaceholder("用户名");
usernameField.setPreferredSize(textFieldDimension);
usernameField.setFont(FontUtil.getDefaultFont(14));
usernameField.setForeground(Colors.FONT_BLACK);
usernameField.setMargin(new Insets(0, 15, 0, 0));
usernameField.setText("wangxin");
passwordField = new RCPasswordField();
passwordField.setPreferredSize(textFieldDimension);
passwordField.setPlaceholder("密码");
// passwordField.setBorder(new RCBorder(RCBorder.BOTTOM,
// Colors.LIGHT_GRAY));
passwordField.setFont(FontUtil.getDefaultFont(14));
passwordField.setForeground(Colors.FONT_BLACK);
passwordField.setMargin(new Insets(0, 15, 0, 0));
passwordField.setText("1");
loginButton = new RCButton("登 录", Colors.MAIN_COLOR, Colors.MAIN_COLOR_DARKER, Colors.MAIN_COLOR_DARKER);
loginButton.setFont(FontUtil.getDefaultFont(14));
loginButton.setPreferredSize(new Dimension(300, 40));
statusLabel = new JLabel();
statusLabel.setForeground(Colors.RED);
statusLabel.setText("密码不正确");
statusLabel.setVisible(false);
usernameField.setText(readName());
passwordField.setText(readPassword());
}
private void setup() {
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.LINE_START;
c.gridx = 1;
c.gridy = 1;
c.weightx = 0.0;
c.weighty = 0.0;
c.insets = new Insets(1, 2, 1, 2);
modeLabel = new JLabel(getString(KEY_MODE_TEXT));
ConfigManager manager = getUser().getPreferencesManager();
Font labelFont = manager.getFontValue(KEY_LABEL_FONT, DEFAULT_FONT);
labelFont = new JLabel().getFont().deriveFont(labelFont.getStyle(), labelFont.getSize2D());
labelFont = getUser().scaleFont(labelFont);
Font modeFont = manager.getFontValue(KEY_MODE_FONT, DEFAULT_FONT);
modeFont = new JLabel().getFont().deriveFont(modeFont.getStyle(), modeFont.getSize2D());
modeFont = getUser().scaleFont(modeFont);
modeLabel.setFont(labelFont);
modeLabel.setForeground(getModeSelectColor());
add(modeLabel, c);
oldMode = getUser().getCurrentEntryMode();
for (EntryMode mode : EntryMode.values()) {
JLabel label = new JLabel(getString(mode.getI18nKey()));
label.setFont(modeFont);
label.setForeground(getColorFor(mode));
String modeTooltipKey = "tooltip." + mode.getI18nKey();
String modeTooltipText = getString(modeTooltipKey);
if (!modeTooltipKey.equals(modeTooltipText)) {
label.setToolTipText(modeTooltipText);
}
setBorderFor(label, mode.equals(oldMode));
modeMap.put(mode, label);
c.gridx++;
label.addFocusListener(new FocusAdapter() {
private final ModeIndicatorUser user = getUser();
@Override
public void focusGained(FocusEvent e) {
user.setCurrentEntryMode(mode);
}
});
add(label, c);
}
}