List of usage examples for javax.swing JLabel setBackground
@BeanProperty(preferred = true, visualUpdate = true, description = "The background color of the component.") public void setBackground(Color bg)
From source file:Main.java
public Main() { super("JLabel Demo"); setSize(600, 100);//from ww w . j a va 2 s . c o 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() { 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);/*from ww w . j a v a 2 s.com*/ label.setBackground(tf.getBackground()); label.setPreferredSize(new Dimension(label.getPreferredSize().width, tf.getPreferredSize().height)); p.setBorder(tf.getBorder()); 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:Main.java
private void configureRenderer(JLabel renderer, Object value) { renderer.setBackground((Color) value); }
From source file:Main.java
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);//from w ww . ja v a 2 s. co m if (value instanceof Color) { renderer.setBackground((Color) value); } renderer.setPreferredSize(preferredSize); return renderer; }
From source file:ComboTableCellRenderer.java
private void configureRenderer(JLabel renderer, Object value) { if ((value != null) && (value instanceof Color)) { renderer.setText(value.toString()); renderer.setBackground((Color) value); } else {//from w ww . ja v a 2s .c om renderer.setText((String) value); } }
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);// w w w .jav a2s. c o m jif.getContentPane().add(label); 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:es.emergya.ui.base.Message.java
private void inicializar(final String texto) { log.trace("inicializar(" + texto + ")"); final Message message_ = this; SwingUtilities.invokeLater(new Runnable() { @Override//from w ww . jav a 2 s.com public void run() { log.trace("Sacamos un nuevo mensaje: " + texto); JDialog frame = new JDialog(window.getFrame(), true); frame.setUndecorated(true); frame.getContentPane().setBackground(Color.WHITE); frame.setLocation(150, window.getHeight() - 140); frame.setSize(new Dimension(window.getWidth() - 160, 130)); frame.setName("Incoming Message"); frame.setBackground(Color.WHITE); frame.getRootPane().setBorder(new MatteBorder(4, 4, 4, 4, color)); frame.setLayout(new BorderLayout()); if (font != null) frame.setFont(font); JLabel icon = new JLabel(new ImageIcon(this.getClass().getResource("/images/button-ok.png"))); icon.setToolTipText("Cerrar"); icon.removeMouseListener(null); icon.addMouseListener(new Cerrar(frame, message_)); JLabel text = new JLabel(texto); text.setBackground(Color.WHITE); text.setForeground(Color.BLACK); frame.add(text, BorderLayout.WEST); frame.add(icon, BorderLayout.EAST); frame.setVisible(true); } }); }
From source file:DesktopManagerDemo.java
public void newFrame() { JInternalFrame jif = new JInternalFrame("Frame " + m_count, true, true, true, true); 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);// w w w .j a v a2 s.c om jif.getContentPane().add(label); 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);//w ww . j a va 2 s. c o m label.setBackground(color); 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);/*w w w . ja v a 2s.co m*/ label.setBackground(color); label.setForeground(Color.black); label.setBorder(BorderFactory.createLineBorder(Color.black)); label.setPreferredSize(new Dimension(140, 140)); return label; }