Java Code Examples for javax.swing.JLabel.setOpaque()

The following are Jave code examples for showing how to use setOpaque() of the javax.swing.JLabel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: RSSFeed.java   View Source Code Vote up 6 votes
private JComponent buildContentLoadingLabel() {
    JLabel label = new JLabel( BundleSupport.getLabel( "ContentLoading" ) ); // NOI18N
    label.setHorizontalAlignment( JLabel.CENTER );
    label.setVerticalAlignment( JLabel.CENTER );
    label.setOpaque( false );
    Component header = getContentHeader();
    if( null != header ) {
        JPanel panel = new JPanel( new GridBagLayout() );
        panel.setOpaque( false );
        panel.add( header, new GridBagConstraints(0,0,1,1,1.0,1.0,
            GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(0,0,0,0),0,0 ) );
        panel.add( label, new GridBagConstraints(0,1,1,1,1.0,1.0,
            GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(0,0,0,0),0,0 ) );
        panel.setBorder( BorderFactory.createEmptyBorder(40, 0, 40, 0));
        return panel;
    }
    label.setBorder( BorderFactory.createEmptyBorder(40, 0, 40, 0));
    return label;
}
 
Example 2
Project: scorekeeperfrontend   File: CarRenderer.java   View Source Code Vote up 6 votes
public MyPanel()
{
    setLayout(new MigLayout("ins 5, gapx 12, gapy 1", "[][35!][100:500:10000]", ""));
    setBorder(new UnderlineBorder(new Color(180, 180, 180)));

    status = new JLabel();
    status.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 14));
    status.setOpaque(false);
    add(status, "ay center, spany 2");

    payment = new JLabel();
    payment.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 12));
    add(payment, "ax right, spany 2");

    carinfo = new JLabel();
    carinfo.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 12));
    add(carinfo, "gap 0, wrap");

    cardesc = new JLabel();
    cardesc.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
    add(cardesc, "gap 0");
}
 
Example 3
Project: DicomViewer   File: FlyingToolTip.java   View Source Code Vote up 6 votes
public FlyingToolTip(final FlyingToolTipListener source) {
    this.source = source;
    label = new JLabel("test", JLabel.CENTER) {
        @Override
        public void paintComponent(Graphics g) {
            Graphics2D g2 = (Graphics2D) g.create();
            int w = getWidth(), h = getHeight();
            g.setColor(getBackground());
            g.fillRect(0,0,w,h);

            if (path != null) {                    
                g2.setStroke(new BasicStroke(4f));
                g2.setColor(getForeground());
                g2.draw(path);
            }
            setOpaque(false);
            super.paintComponent(g2);
            setOpaque(true);
            g2.dispose();
        }
    };    
    label.setBorder(new EmptyBorder(2,4,10,4));
    label.setOpaque(true);
}
 
Example 4
Project: Tarski   File: EditorPalette.java   View Source Code Vote up 6 votes
/**
 * 
 */
public void setSelectionEntry(JLabel entry, mxGraphTransferable t)
{
	JLabel previous = selectedEntry;
	selectedEntry = entry;

	if (previous != null)
	{
		previous.setBorder(null);
		previous.setOpaque(false);
	}

	if (selectedEntry != null)
	{
		selectedEntry.setBorder(ShadowBorder.getSharedInstance());
		selectedEntry.setOpaque(true);
	}

	eventSource.fireEvent(new mxEventObject(mxEvent.SELECT, "entry",
			selectedEntry, "transferable", t, "previous", previous));
}
 
Example 5
Project: incubator-netbeans   File: SearchResultRenderer.java   View Source Code Vote up 6 votes
private void configRenderer () {
    resultLabel = new JLabel();
    resultLabel.setOpaque(true);
    resultLabel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 4));

    itemPanel = new JPanel();
    itemPanel.setBackground(QuickSearchComboBar.getResultBackground());
    itemPanel.setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 3));
    itemPanel.setLayout(new BorderLayout());
    itemPanel.add(resultLabel, BorderLayout.CENTER);

    rendererComponent = new JPanel();
    rendererComponent.setLayout(new BorderLayout());
    rendererComponent.add(itemPanel, BorderLayout.CENTER);
    
    dividerLine = new JPanel();
    dividerLine.setBackground(QuickSearchComboBar.getPopupBorderColor());
    dividerLine.setPreferredSize(new Dimension(dividerLine.getPreferredSize().width, 1));
}
 
Example 6
Project: incubator-netbeans   File: ProjectSelectionPanel.java   View Source Code Vote up 6 votes
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
        boolean isSelected, boolean hasFocus, int row, int column) {
    Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    if (c instanceof JLabel) {
        JLabel label = (JLabel)c;
        label.setOpaque(isSelected);
        EclipseProject project = projects[row];
        if (project.isImportSupported()) {
            label.setIcon(project.getProjectTypeFactory().getProjectTypeIcon());
        } else {
            label.setIcon(null);
        }
    }
    return c;
}
 
Example 7
Project: litiengine   File: JCheckBoxList.java   View Source Code Vote up 5 votes
@Override
public Component getListCellRendererComponent(
    JList<? extends JCheckBox> list, JCheckBox value, int index,
    boolean isSelected, boolean cellHasFocus) {
  JPanel panel = new JPanel(new BorderLayout());

  JCheckBox checkbox = value;
  final JCheckBox newCheck = new JCheckBox();
  final JLabel newLabel = new JLabel(checkbox.getText());
  newCheck.setSelected(checkbox.isSelected());
  // Drawing checkbox, change the appearance here
  newCheck.setBackground(isSelected ? getSelectionBackground()
      : getBackground());
  newCheck.setForeground(isSelected ? getSelectionForeground()
      : getForeground());
  newCheck.setEnabled(isEnabled());
  newCheck.setFont(getFont());
  newCheck.setFocusPainted(false);
  newCheck.setBorderPainted(true);
  newCheck.setBorder(isSelected ? UIManager
      .getBorder("List.focusCellHighlightBorder") : noFocusBorder);
  newLabel.setOpaque(true);
  newLabel.setBackground(isSelected ? getSelectionBackground()
      : getBackground());
  newLabel.setForeground(isSelected ? getSelectionForeground()
      : getForeground());
  newLabel.setEnabled(isEnabled());
  newLabel.setFocusable(false);
  newLabel.setFont(getFont());
  newLabel.setBorder(isSelected ? UIManager
      .getBorder("List.focusCellHighlightBorder") : noFocusBorder);
  newLabel.setIcon(checkbox.getIcon());

  panel.add(newCheck, BorderLayout.WEST);
  panel.add(newLabel, BorderLayout.CENTER);
  return panel;
}
 
Example 8
Project: Recaf   File: RenderFormatter.java   View Source Code Vote up 5 votes
/**
 * Sets the desired look of the lavel.
 * 
 * @param label
 *            Label to apply style to.
 * @param selected
 *            If label is selected or not.
 */
default void formatLabel(JLabel label, boolean selected) {
	label.setFont(Fonts.monospace);
	label.setOpaque(true);
	label.setBorder(BorderFactory.createEtchedBorder());
	if (selected) {
		label.setBackground(Color.decode(getTheme().listItemSelected));
	} else {
		label.setBackground(Color.decode(getTheme().listItemBackground));
	}
}
 
Example 9
Project: freecol   File: Utility.java   View Source Code Vote up 5 votes
/**
 * Gets a label containing a localized message using the header font.
 *
 * @param key The message key to use.
 * @param alignment The alignment.
 * @param size The font size.
 * @return A suitable {@code JLabel}.
 */
public static JLabel localizedHeaderLabel(String key, int alignment,
                                          FontLibrary.FontSize size) {
    String text = Messages.message(key);
    JLabel header = new JLabel(text, alignment);
    header.setFont(FontLibrary.createCompatibleFont(
        text, FontLibrary.FontType.HEADER, size));
    header.setOpaque(false);
    return header;
}
 
Example 10
Project: QN-ACTR-Release   File: AllStationsParametersPanel.java   View Source Code Vote up 5 votes
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
	JLabel label = new JLabel(stationData.getStationName(value), JMTImageLoader.loadImage(stationData.getStationType(value) + "Combo"),
			SwingConstants.LEFT);
	label.setOpaque(true);
	label.setBorder(new LineBorder(cellHasFocus ? Color.BLUE : Color.WHITE));
	label.setBackground(isSelected ? list.getSelectionBackground() : Color.WHITE);
	label.setForeground(isSelected ? list.getSelectionForeground() : Color.BLACK);
	label.setFont(isSelected ? label.getFont().deriveFont(Font.BOLD) : label.getFont().deriveFont(Font.ROMAN_BASELINE));
	return label;
}
 
Example 11
Project: freecol   File: Utility.java   View Source Code Vote up 5 votes
public static JLabel localizedHeaderLabel(StringTemplate template,
                                          int alignment,
                                          FontLibrary.FontSize size) {
    String text = Messages.message(template);
    JLabel header = new JLabel(text, alignment);
    header.setFont(FontLibrary.createCompatibleFont(
        text, FontLibrary.FontType.HEADER, size));
    header.setOpaque(false);
    return header;
}
 
Example 12
Project: jmt   File: Sectors3DPanel.java   View Source Code Vote up 5 votes
/**
 * Builds a new Sectors3D Panel to show results of 3-class models
 * @param s3d results vector
 * @param classNames array with class names
 */
public Sectors3DPanel(Vector<Object> s3d, String[] classNames) {
	super(new BorderLayout());
	this.s3d = s3d;
	this.classNames = classNames;
	this.setBackground(BGCOLOR);
	this.setBorder(BorderFactory.createEtchedBorder());

	// Label to show coordinates
	coordLabel = new JLabel();
	coordLabel.setBorder(BorderFactory.createEtchedBorder());
	coordLabel.setVisible(false);
	coordLabel.setOpaque(true);
	// Puts label on south-east corner
	JPanel tmp = new JPanel(new BorderLayout());
	tmp.add(coordLabel, BorderLayout.EAST);
	tmp.setOpaque(false);
	this.add(tmp, BorderLayout.SOUTH);

	// Adds a mouseListener to show graph coordinates
	this.addMouseMotionListener(new MouseMotionAdapter() {
		@Override
		public void mouseMoved(MouseEvent e) {
			if (isShown) {
				String coord = getCoordinates(e.getX(), e.getY());
				if (coord != null) {
					coordLabel.setText(coord);
					coordLabel.setVisible(true);
					Sectors3DPanel.this.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
				} else {
					coordLabel.setText("");
					coordLabel.setVisible(false);
					Sectors3DPanel.this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
				}
			}
		}
	});
}
 
Example 13
Project: JDigitalSimulator   File: Guitilities.java   View Source Code Vote up 5 votes
public static GradientPanel createGradientTitle(String title) {
	GradientPanel panel = new GradientPanel(UIManager.getColor(TITLE_GRADIENT_COLOR_A), UIManager.getColor(TITLE_GRADIENT_COLOR_B));
	panel.setLayout(new BorderLayout());
	panel.setBorder(TITLE_BORDER);
	panel.setPreferredSize(new Dimension(0, 40));
	JLabel label = new JLabel(title);
	label.setOpaque(false);
	label.setFont(UIManager.getFont(TITLE_FONT));
	label.setForeground(UIManager.getColor(TITLE_FOREGROUND));
	label.setHorizontalAlignment(JLabel.LEADING);
	panel.add(label, BorderLayout.CENTER);
	return panel;
}
 
Example 14
Project: incubator-netbeans   File: SwitcherTable.java   View Source Code Vote up 4 votes
@Override
public Component prepareRenderer(
        TableCellRenderer renderer,
        int row,
        int column) {
    
    SwitcherTableItem item
            = (SwitcherTableItem) getSwitcherTableModel().getValueAt(row, column);
    
    boolean selected = row == getSelectedRow() &&
            column == getSelectedColumn() && item != null;
    
    Component ren = renderer.getTableCellRendererComponent(this, item,
            selected, selected, row, column);
    JLabel lbl = null;
    if (ren instanceof JLabel) {
        // #199007: Swing HTML renderer does a poor job of truncating long labels
        JLabel prototype = (JLabel) ren;
        lbl = HtmlRenderer.createLabel();
        if( lbl instanceof HtmlRenderer.Renderer ) {
            ((HtmlRenderer.Renderer)lbl).setRenderStyle( HtmlRenderer.STYLE_TRUNCATE );
        }
        lbl.setForeground(prototype.getForeground());
        lbl.setBackground(prototype.getBackground());
        lbl.setFont(prototype.getFont());
        // border, text will be overwritten below anyway
        ren = lbl;
    }
    
    if (item == null) {
        // it's a filler space, we're done
        if( null != lbl ) {
            lbl.setOpaque(false);
            lbl.setIcon(null);
        }
        return ren;
    }
    
    Icon icon = item.getIcon();
    if (icon == null || icon.getIconWidth() == 0 ) {
        icon = nullIcon;
    }
    boolean active = item.isActive();
    if( null != lbl ) {
        lbl.setText((selected || (active && !TABNAMES_HTML)) ? stripHtml( item.getHtmlName() ) : item.getHtmlName());
        lbl.setBorder(rendererBorder);
        if( showIcons ) {
            lbl.setIcon(icon);
            lbl.setIconTextGap(26 - icon.getIconWidth());
        }
    }
    
    if (active) {
        if (TABNAMES_HTML) {
            if( null != lbl )
                lbl.setText(lbl.getText() + " ←"); // NOI18N
        } else if (Utilities.isWindows()) {
            ren.setFont(getFont().deriveFont(Font.BOLD, getFont().getSize()));
        } else {
            // don't use deriveFont() - see #49973 for details
            ren.setFont(new Font(getFont().getName(), Font.BOLD, getFont().getSize()));
        }
    }

    if( null != lbl )
        lbl.setOpaque(true);
    
    return ren;
}
 
Example 15
Project: incubator-netbeans   File: FixDuplicateImportStmts.java   View Source Code Vote up 4 votes
private void initComponentsMore(ImportData data, boolean removeUnusedImports) {
    contentPanel.setLayout( new GridBagLayout() );
    contentPanel.setBackground( UIManager.getColor("Table.background") ); //NOI18N
    jScrollPane1.setBorder( UIManager.getBorder("ScrollPane.border") ); //NOI18N
    jScrollPane1.getVerticalScrollBar().setUnitIncrement( new JLabel("X").getPreferredSize().height );
    jScrollPane1.getVerticalScrollBar().setBlockIncrement( new JLabel("X").getPreferredSize().height*10 );
    
    if (data.variants.length > 0 ) {
    
        int row = 0;

        combos = new JComboBox[data.variants.length];

        Font monoSpaced = new Font( "Monospaced", Font.PLAIN, new JLabel().getFont().getSize() );
        FocusListener focusListener = new FocusListener() {
            public void focusGained(FocusEvent e) {
                Component c = e.getComponent();
                Rectangle r = c.getBounds();
                contentPanel.scrollRectToVisible( r );
            }
            public void focusLost(FocusEvent arg0) {
            }
        };
        for (int i=0; i < data.variants.length; i++){
            combos[i] = createComboBox(data.variants[i], data.defaults[i], monoSpaced, focusListener );

            JLabel lblSimpleName = new JLabel(data.simpleNames[i]);
            lblSimpleName.setOpaque( false );
            lblSimpleName.setFont( monoSpaced );
            lblSimpleName.setLabelFor( combos[i] );

            contentPanel.add( lblSimpleName, new GridBagConstraints(0,row,1,1,0.0,0.0,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(3,5,2,5),0,0) );
            contentPanel.add( combos[i], new GridBagConstraints(1,row++,1,1,1.0,0.0,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL,new Insets(3,5,2,5),0,0) );
        }

        contentPanel.add( new JLabel(), new GridBagConstraints(2,row,2,1,0.0,1.0,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(0,0,0,0),0,0) );

        Dimension d = contentPanel.getPreferredSize();
        d.height = getRowHeight() * Math.min(combos.length, 6);
        jScrollPane1.getViewport().setPreferredSize( d );
    } else {
        contentPanel.add( new JLabel(getBundleString("FixDupImportStmts_NothingToFix")), new GridBagConstraints(0,0,1,1,1.0,1.0,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(20,20,20,20),0,0) );
    }
    
    // load localized text into widgets:
    lblTitle.setText(getBundleString("FixDupImportStmts_IntroLbl")); //NOI18N
    lblHeader.setText(getBundleString("FixDupImportStmts_Header")); //NOI18N
    
    checkUnusedImports = new JCheckBox();
    Mnemonics.setLocalizedText(checkUnusedImports, getBundleString("FixDupImportStmts_UnusedImports")); //NOI18N
    bottomPanel.add( checkUnusedImports, BorderLayout.WEST );
    checkUnusedImports.setEnabled(true);
    checkUnusedImports.setSelected(removeUnusedImports);
}
 
Example 16
Project: FreeCol   File: FirstContactDialog.java   View Source Code Vote up 4 votes
/**
 * Create an FirstContactDialog.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param frame The owner frame.
 * @param player The {@code Player} making contact.
 * @param other The {@code Player} to contact.
 * @param tile An optional {@code Tile} on offer.
 * @param settlementCount The number of settlements the other
 *     player has.
 */
public FirstContactDialog(FreeColClient freeColClient, JFrame frame,
        Player player, Player other, Tile tile, int settlementCount) {
    super(freeColClient, frame);

    MigPanel panel
        = new MigPanel(new MigLayout("wrap 1", "[center]", "[]20"));
    panel.setOpaque(false);

    String headerKey = BASE_KEY + other.getNation().getSuffix();
    String imageKey = IMAGE_BASE_KEY + other.getNationResourceKey();
    if (!Messages.containsKey(headerKey)) {
        headerKey = BASE_KEY + NATIVES_KEY;
        imageKey = IMAGE_BASE_KEY + NATIVES_KEY;
    }
    JLabel header = Utility.localizedHeaderLabel(headerKey,
        SwingConstants.LEADING, FontLibrary.FontSize.MEDIUM);
    JLabel image
        = new JLabel(new ImageIcon(ResourceManager.getImage(imageKey)));
    image.setOpaque(false);

    JTextArea tutorial = null;
    if (!player.hasContactedIndians() && freeColClient.tutorialMode()) {
        tutorial = Utility.localizedTextArea(TUTORIAL_KEY);
    }

    String messageId = (tile != null)
        ? "firstContactDialog.welcomeOffer.text"
        : "firstContactDialog.welcomeSimple.text";
    String type = ((IndianNationType)other.getNationType())
        .getSettlementTypeKey(true);
    JTextArea text = Utility.localizedTextArea(StringTemplate
        .template(messageId)
        .addStringTemplate("%nation%", other.getNationLabel())
        .addName("%camps%", Integer.toString(settlementCount))
        .add("%settlementType%", type));

    // Resize the text areas to better match the image.
    int columns = (int)Math.floor(text.getColumns()
        * image.getPreferredSize().getWidth()
        / text.getPreferredSize().getWidth());
    text.setColumns(columns);
    text.setSize(text.getPreferredSize());
    if (tutorial != null) {
        tutorial.setColumns(columns);
        tutorial.setSize(tutorial.getPreferredSize());
    }

    panel.add(header);
    panel.add(image);
    if (tutorial != null) panel.add(tutorial);
    panel.add(text);
    panel.setSize(panel.getPreferredSize());

    ImageIcon icon = new ImageIcon(
        getImageLibrary().getMiscIconImage(other.getNation()));
    initializeConfirmDialog(frame, false, panel, icon, "yes", "no");
}
 
Example 17
Project: KernelHive   File: WorkflowProgressViewerPanel.java   View Source Code Vote up 4 votes
private JLabel createSquare(String text, Color color) {
	JLabel cell = new JLabel(text);
	cell.setBackground(color);
	cell.setOpaque(true);
	return cell;
}
 
Example 18
Project: freecol   File: Utility.java   View Source Code Vote up 3 votes
/**
 * Get a JLabel with Messages.message(template) as text.
 *
 * @param template The {@code StringTemplate} to use.
 * @param icon The icon to use.
 * @param alignment The alignment.
 * @return The {@code JLabel}.
 */
public static JLabel localizedLabel(StringTemplate template, Icon icon,
                                    int alignment) {
    JLabel label = new JLabel(Messages.message(template), icon, alignment);
    label.setOpaque(false);
    return label;
}
 
Example 19
Project: QN-ACTR-Release   File: AllBlockingRegionsPanel.java   View Source Code Vote up 3 votes
/**
* Returns the component used for drawing the cell.  This method is
* used to configure the renderer appropriately before drawing.
*
* @param    table        the <code>JTable</code> that is asking the
* renderer to draw; can be <code>null</code>
* @param    value        the value of the cell to be rendered.  It is
* up to the specific renderer to interpret
* and draw the value.  For example, if
* <code>value</code>
* is the string "true", it could be rendered as a
* string or it could be rendered as a check
* box that is checked.  <code>null</code> is a
* valid value
* @param    isSelected    true if the cell is to be rendered with the
* selection highlighted; otherwise false
* @param    hasFocus    if true, render cell appropriately.  For
* example, put a special border on the cell, if
* the cell can be edited, render in the color used
* to indicate editing
* @param    row     the row index of the cell being drawn.  When
* drawing the header, the value of
* <code>row</code> is -1
* @param    column     the column index of the cell being drawn
*/
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
	JLabel label = new JLabel(bd.getRegionName(value), JMTImageLoader.loadImage("BlockingCombo"), SwingConstants.LEFT);
	label.setOpaque(true);
	label.setBorder(new LineBorder(hasFocus ? Color.BLUE : Color.WHITE));
	label.setBackground(isSelected ? table.getSelectionBackground() : Color.WHITE);
	label.setForeground(isSelected ? table.getSelectionForeground() : Color.BLACK);
	label.setFont(isSelected ? label.getFont().deriveFont(Font.BOLD) : label.getFont().deriveFont(Font.ROMAN_BASELINE));
	return label;
}
 
Example 20
Project: freecol   File: Utility.java   View Source Code Vote up 2 votes
/**
 * Get a JLabel with Messages.message(template) as text.
 *
 * @param template The {@code StringTemplate} to use.
 * @return The {@code JLabel}.
 */
public static JLabel localizedLabel(StringTemplate template) {
    JLabel label = new JLabel(Messages.message(template));
    label.setOpaque(false);
    return label;
}