JLabel: setOpaque(boolean isOpaque) : JLabel « javax.swing « Java by API






JLabel: setOpaque(boolean isOpaque)

 
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

public class Main extends JFrame {
  public Main() {
    super("JLabel Demo");
    setSize(600, 100);

    JPanel content = new JPanel(new GridLayout(1, 4, 4, 4));

    JLabel label = new JLabel("Java2s");
    label.setBackground(Color.white);
    content.add(label);

    label = new JLabel("Java2s", SwingConstants.CENTER);
    label.setOpaque(true);
    label.setBackground(Color.white);
    content.add(label);

    label = new JLabel("Java2s");
    label.setFont(new Font("Helvetica", Font.BOLD, 18));
    label.setOpaque(true);
    label.setBackground(Color.white);
    content.add(label);

    ImageIcon image = new ImageIcon("java2sLogo.gif");
    label = new JLabel("Java2s", image, SwingConstants.RIGHT);
    label.setVerticalTextPosition(SwingConstants.TOP);
    label.setOpaque(true);
    label.setBackground(Color.white);
    content.add(label);

    getContentPane().add(content);
    setVisible(true);
  }

  public static void main(String args[]) {
    new Main();
  }
}

   
  








Related examples in the same category

1.JLabel.BOTTOM
2.JLabel.CENTER
3.JLabel.LEFT
4.JLabel.RIGHT
5.JLabel.TOP
6.new JLabel(Icon icon)
7.new JLabel(Icon i, int alignment)
8.new JLabel(String htmlString) (Multi-line Label)
9.new JLabel(String text, int horizontalAlignment)
10.new JLabel(String text, Icon icon, int horizontalAlignment)
11.JLabel: addMouseMotionListener(MouseMotionListener l)
12.JLabel: getTransferHandler()
13.JLabel: setBoder(Border border)
14.JLabel: setBounds(int x, int y, int width, int height)
15.JLabel: setDisplayedMnemonic(int key) (KeyEvent.VK_U)
16.JLabel: setDisplayedMnemonicIndex(int index)
17.JLabel: setLabelFor(Component c)
18.JLabel: setText(String str)
19.JLabel: setHorizontalTextPosition(int align)
20.JLabel: setIcon(Icon icon)
21.JLabel: setPreferredSize(Dimension preferredSize)
22.JLabel: setToolTipText(String text)
23.JLabel: setVerticalAlignment(int alignment)
24.JLabel: setVerticalTextPosition(int align)
25.extends JLabel