List of usage examples for javax.swing JLabel setForeground
@BeanProperty(preferred = true, visualUpdate = true, description = "The foreground color of the component.") public void setForeground(Color fg)
From source file:ColorDrag.java
public static void main(String args[]) { // Create two JLabel objects final JLabel label1 = new JLabel("Drag here"); JLabel label2 = new JLabel("Drop here"); // Register TransferHandler objects on them: label1 transfers its // foreground color and label2 transfers its background color. label1.setTransferHandler(new TransferHandler("foreground")); label2.setTransferHandler(new TransferHandler("background")); // Give label1 a foreground color other than the default // Make label2 opaque so it displays its background color label1.setForeground(new Color(100, 100, 200)); label2.setOpaque(true);//from w w w .j a va2 s . com // Now look for drag gestures over label1. When one occurs, // tell the TransferHandler to begin a drag. // Exercise: modify this gesture recognition so that the drag doesn't // begin until the mouse has moved 4 pixels. This helps to keep // drags distinct from sloppy clicks. To do this, you'll need both // a MouseListener and a MouseMotionListener. label1.addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { TransferHandler handler = label1.getTransferHandler(); handler.exportAsDrag(label1, e, TransferHandler.COPY); } }); // Create a window, add the labels, and make it all visible. JFrame f = new JFrame("ColorDrag"); f.getContentPane().setLayout(new FlowLayout()); f.getContentPane().add(label1); f.getContentPane().add(label2); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame("JColorChooser Popup"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JLabel label = new JLabel("www.java2s.com", JLabel.CENTER); label.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48)); frame.add(label, BorderLayout.SOUTH); final JColorChooser colorChooser = new JColorChooser(label.getBackground()); colorChooser.setBorder(BorderFactory.createTitledBorder("Pick Color for java2s.com")); ColorSelectionModel model = colorChooser.getSelectionModel(); ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { Color newForegroundColor = colorChooser.getColor(); label.setForeground(newForegroundColor); }/*ww w . j a v a 2s . co m*/ }; model.addChangeListener(changeListener); frame.add(colorChooser, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void errorLabel(JLabel label) { label.setForeground(new Color(192, 0, 0)); italicBoldLabel(label);/*from w w w .j a v a2s . c o m*/ }
From source file:Main.java
public static void addSeparator(JPanel panel, String text) { JLabel l = createLabel(text); l.setForeground(LABEL_COLOR); panel.add(l, "gapbottom 1, span, split 2, aligny center"); panel.add(configureActiveComponent(new JSeparator()), "gapleft rel, growx"); }
From source file:Main.java
public static JLabel modifyLabelFont(JLabel label, int style, int delta) { Font font = label.getFont();//from w w w.ja va2 s . c o m label.setFont(font.deriveFont(style, font.getSize() + delta)); label.setForeground(new Color(140, 140, 140)); return label; }
From source file:Main.java
/** * Creates a label with a specific font and color. * * @param text the text for the label.//from www. j a va 2s . c o m * @param font the font. * @param color the color. * * @return The label. */ public static JLabel createJLabel(final String text, final Font font, final Color color) { final JLabel result = new JLabel(text); result.setFont(font); result.setForeground(color); return result; }
From source file:net.sf.texprinter.utils.UIUtils.java
/** * Formats a label as a title. The idea behind this method is to make * a JLabel component to look fancy when acting as a title to a window. * /*from w w w .jav a 2s .c o m*/ * @param label The label to be formatted as a title. */ public static void formatLabelAsTitle(JLabel label) { // if it's not Linux if (!SystemUtils.IS_OS_LINUX) { // simply increase the font size label.setFont(label.getFont().deriveFont(14f)); } else { // it's Linux, so add a bold style too. label.setFont(label.getFont().deriveFont(Font.BOLD, 14f)); } // paint it as blue label.setForeground(new Color(35, 107, 178)); }
From source file:Main.java
public Main() { JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5)); simplePanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); JLabel titleLabel = new JLabel("TITLE BORDERS", JLabel.CENTER); titleLabel.setForeground(Color.red.darker()); add(simplePanel);/*w ww . j a va 2s. c om*/ }
From source file:Main.java
public Main() { JPanel buttonPanel = new JPanel(); buttonPanel.add(new JButton("Foo")); buttonPanel.add(Box.createHorizontalStrut(10)); buttonPanel.add(new JButton("Bar")); String[] columnNames = { "Mon", "Tues", "Wed" }; DefaultTableModel model = new DefaultTableModel(columnNames, 25); JTable table = new JTable(model); JScrollPane scrollPane = new JScrollPane(table); scrollPane.getViewport().setPreferredSize(table.getPreferredSize()); JLabel southLabel = new JLabel("OK!"); southLabel.setForeground(Color.white); JPanel southPanel = new JPanel(); southPanel.add(southLabel);//from w ww. j ava 2 s . co m setLayout(new BorderLayout(5, 5)); add(buttonPanel, BorderLayout.NORTH); add(scrollPane, BorderLayout.CENTER); add(southPanel, BorderLayout.SOUTH); }
From source file:Main.java
public Main() { super("JLayeredPane Demo"); setSize(256, 256);//from ww w. ja v a 2 s .c om JPanel content = new JPanel(); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); content.setOpaque(false); JLabel label1 = new JLabel("Username:"); label1.setForeground(Color.white); content.add(label1); JTextField field = new JTextField(15); content.add(field); JLabel label2 = new JLabel("Password:"); label2.setForeground(Color.white); content.add(label2); JPasswordField fieldPass = new JPasswordField(15); content.add(fieldPass); setLayout(new FlowLayout()); add(content); ((JPanel) getContentPane()).setOpaque(false); ImageIcon earth = new ImageIcon("largeJava2sLogo.png"); JLabel backlabel = new JLabel(earth); getLayeredPane().add(backlabel, new Integer(Integer.MIN_VALUE)); backlabel.setBounds(0, 0, earth.getIconWidth(), earth.getIconHeight()); super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); }