Example usage for javax.swing JLabel setOpaque

List of usage examples for javax.swing JLabel setOpaque

Introduction

In this page you can find the example usage for javax.swing JLabel setOpaque.

Prototype

@BeanProperty(expert = true, description = "The component's opacity")
public void setOpaque(boolean isOpaque) 

Source Link

Document

If true the component paints every pixel within its bounds.

Usage

From source file:Main.java

public Main() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JPanel p = new JPanel(new BorderLayout());
    JTextField tf = new JTextField(5);
    JLabel label = new JLabel(new ImageIcon("Test.gif"));
    label.setOpaque(true);
    label.setBackground(tf.getBackground());
    label.setPreferredSize(new Dimension(label.getPreferredSize().width, tf.getPreferredSize().height));
    p.setBorder(tf.getBorder());/*from  w  w  w . j a v  a 2  s .co m*/
    tf.setBorder(null);
    p.add(label, BorderLayout.WEST);
    p.add(tf, BorderLayout.CENTER);
    JPanel p1 = new JPanel();
    p1.add(p);
    getContentPane().add(p1);
    pack();
    setLocationRelativeTo(null);
}

From source file:com.opendoorlogistics.studio.tables.grid.HeaderCellRenderer.java

/**
 * /*from   w  w w. j  a  va  2s  .  c o  m*/
 */
protected void initLabel(JLabel label) {
    label.setOpaque(true);
    label.setHorizontalAlignment(SwingConstants.CENTER);
    label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
}

From source file:Main.java

private JPanel createComboLabelPanel(int index, JComboBox<ComboColor> combo) {
    JPanel panel = new JPanel();
    JLabel label = new JLabel(SIGNAL + " " + index);
    label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    label.setOpaque(true);
    combo.addActionListener(new ActionListener() {

        @Override/*from ww w . j a  v  a2 s .c  o m*/
        public void actionPerformed(ActionEvent evt) {
            ComboColor cColor = (ComboColor) combo.getSelectedItem();
            label.setBackground(cColor.getColor());
        }
    });

    panel.add(label);
    panel.add(combo);
    return panel;
}

From source file:Main.java

public Main() {
    mainPanel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
    mainPanel.setLayout(null);// w w w.  j  ava  2 s .  c  o m

    MyMouseAdapter myMouseAdapter = new MyMouseAdapter();
    for (int i = 0; i < LABEL_STRINGS.length; i++) {
        JLabel label = new JLabel(LABEL_STRINGS[i], SwingConstants.CENTER);
        label.setSize(new Dimension(LBL_WIDTH, LBL_HEIGHT));
        label.setOpaque(true);
        Random random = new Random();
        label.setLocation(random.nextInt(WIDTH - LBL_WIDTH), random.nextInt(HEIGHT - LBL_HEIGHT));
        label.setBackground(
                new Color(150 + random.nextInt(105), 150 + random.nextInt(105), 150 + random.nextInt(105)));
        label.addMouseListener(myMouseAdapter);
        label.addMouseMotionListener(myMouseAdapter);

        mainPanel.add(label);
    }
}

From source file:LabelDemo.java

public LabelDemo() {
    super("JLabel Demo");
    setSize(600, 100);// w  w w  .  j  ava2  s . co m

    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);
}

From source file:Main.java

public Main() {
    super("JLabel Demo");
    setSize(600, 100);/*from w  w w.j  ava 2 s .  co m*/

    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);
}

From source file:InternalFrameListenerDemo.java

public void newFrame() {
    JInternalFrame jif = new JInternalFrame("Frame " + m_count, true, true, true, true);
    jif.addInternalFrameListener(this);
    jif.setBounds(20 * (m_count % 10) + m_tencount * 80, 20 * (m_count % 10), 200, 200);
    JLabel label = new JLabel();
    label.setBackground(Color.white);
    label.setOpaque(true);
    jif.getContentPane().add(label);//from  ww  w  .j av a  2s.  c om
    m_desktop.add(jif);
    try {
        jif.setSelected(true);
    } catch (PropertyVetoException pve) {
        System.out.println("Could not select " + jif.getTitle());
    }
    m_count++;
    if (m_count % 10 == 0) {
        if (m_tencount < 3)
            m_tencount++;
        else
            m_tencount = 0;
    }
}

From source file:LayeredPaneDemo.java

private JLabel createColoredLabel(String text, Color color, Point origin) {
    JLabel label = new JLabel(text);
    label.setVerticalAlignment(JLabel.TOP);
    label.setHorizontalAlignment(JLabel.CENTER);
    label.setOpaque(true);
    label.setBackground(color);//  w w  w .jav  a 2s  .com
    label.setForeground(Color.black);
    label.setBorder(BorderFactory.createLineBorder(Color.black));
    label.setBounds(origin.x, origin.y, 140, 140);
    return label;
}

From source file:components.LayeredPaneDemo2.java

private JLabel createColoredLabel(String text, Color color) {
    JLabel label = new JLabel(text);
    label.setVerticalAlignment(JLabel.TOP);
    label.setHorizontalAlignment(JLabel.CENTER);
    label.setOpaque(true);
    label.setBackground(color);//from  w  w  w . j  a  v  a2  s  .c  o m
    label.setForeground(Color.black);
    label.setBorder(BorderFactory.createLineBorder(Color.black));
    label.setPreferredSize(new Dimension(140, 140));
    return label;
}

From source file:com.openbravo.pos.util.ThumbNailBuilder.java

public Image getThumbNailText(Image img, String text) {
    /*//from   ww w  .ja  va  2 s . c o m
     * Create an image containing a thumbnail of the product image,
     * or default image.
     * 
     * Then apply the text of the product name. Use text wrapping.
     * 
     * If the product name is too big for the label, ensure that
     * the first part is displayed.
     */

    img = getThumbNail(img);

    BufferedImage imgtext = new BufferedImage(img.getWidth(null), img.getHeight(null),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = imgtext.createGraphics();

    // The text
    // <p style="width: 100px"> DOES NOT WORK PROPERLY.
    // use width= instead.
    String html = "<html><p style=\"text-align:center\" width=\"" + imgtext.getWidth() + "\">"
            + StringEscapeUtils.escapeHtml(text) + "</p>";

    JLabel label = new JLabel(html);
    label.setOpaque(false);
    //label.setText("<html><center>Line1<br>Line2");
    label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    label.setVerticalAlignment(javax.swing.SwingConstants.TOP);
    Dimension d = label.getPreferredSize();
    label.setBounds(0, 0, imgtext.getWidth(), d.height);

    // The background
    Color c1 = new Color(0xff, 0xff, 0xff, 0x40);
    Color c2 = new Color(0xff, 0xff, 0xff, 0xd0);

    //        Point2D center = new Point2D.Float(imgtext.getWidth() / 2, label.getHeight());
    //        float radius = imgtext.getWidth() / 3;
    //        float[] dist = {0.1f, 1.0f};
    //        Color[] colors = {c2, c1};        
    //        Paint gpaint = new RadialGradientPaint(center, radius, dist, colors);
    Paint gpaint = new GradientPaint(new Point(0, 0), c1, new Point(label.getWidth() / 2, 0), c2, true);

    g2d.drawImage(img, 0, 0, null);
    int ypos = imgtext.getHeight() - label.getHeight();
    int ypos_min = -4; // todo: configurable
    if (ypos < ypos_min)
        ypos = ypos_min; // Clamp label
    g2d.translate(0, ypos);
    g2d.setPaint(gpaint);
    g2d.fillRect(0, 0, imgtext.getWidth(), label.getHeight());
    label.paint(g2d);

    g2d.dispose();

    return imgtext;
}