Java JLabel create information label using color from system settings

Description

Java JLabel create information label using color from system settings

import java.awt.SystemColor;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.Border;

public class Main extends JFrame {
  public static JLabel createInfoLabel(String text) {
    JLabel label = new JLabel(text);
    label.setOpaque(true);//from  w  w  w.  j a v  a 2  s.co  m

    Border inner = BorderFactory.createEmptyBorder(2, 4, 2, 4);
    Border outer = BorderFactory.createLineBorder(SystemColor.info
            .darker());
    label.setBorder(BorderFactory.createCompoundBorder(outer, inner));
    label.setBackground(SystemColor.info);

    return label;
}

  public Main() {
    super("Link JLabel with JTextField");

    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JLabel nameLabel = createInfoLabel("Java demo from demo2s.com.");

    add(nameLabel);

  }

  public static void main(String[] args) {
    Main frame = new Main();
    frame.pack();
    frame.setVisible(true);
  }
}



PreviousNext

Related