Java Code Examples for javax.swing.JLabel#setBackground()
The following examples show how to use
javax.swing.JLabel#setBackground() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TranslationTreeCellRenderer.java From i18n-editor with MIT License | 6 votes |
@Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { TranslationTreeNode node = (TranslationTreeNode) value; TranslationTreeModel model = (TranslationTreeModel) tree.getModel(); JLabel l = (JLabel) super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); l.setOpaque(true); l.setForeground(tree.getForeground()); l.setBackground(tree.getBackground()); if (!node.isRoot() && (node.hasError() || model.hasErrorChildNode(node))) { l.setIcon(new TranslationTreeStatusIcon(StatusIconType.Warning)); } if (node.isRoot()) { l.setIcon(ROOT_ICON); } if (selected) { l.setBackground(selectionBackground); } return l; }
Example 2
Source File: DeckCellRenderer.java From magarena with GNU General Public License v3.0 | 6 votes |
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { String deckName = (String) value; JLabel lbl = new JLabel(deckName); lbl.setOpaque(true); if (isSelected) { lbl.setForeground(table.getSelectionForeground()); lbl.setBackground(table.getSelectionBackground()); } else { lbl.setForeground(table.getForeground()); lbl.setBackground(table.getBackground()); } Point mp = MouseInfo.getPointerInfo().getLocation(); SwingUtilities.convertPointFromScreen(mp, table); int mRow = table.rowAtPoint(mp); int mCol = table.columnAtPoint(mp); if (row == mRow && column == mCol) { lbl.setForeground(Color.blue); lbl.setFont(withUnderline); } return lbl; }
Example 3
Source File: PerformanceThread.java From cloudExplorer with GNU General Public License v3.0 | 6 votes |
void display(double throughput, double iops ) { if (!operation) { type_operation = "GET"; } else { type_operation = "PUT"; } JLabel throughputIcon = new JLabel("\n Average " + type_operation + " Throughput \n\n" + Double.toString(throughput) + " MB/s"); throughputIcon.setFont(throughputIcon.getFont().deriveFont(19.0f)); throughputIcon.setForeground(BLUE); throughputIcon.setBackground(WHITE); JLabel iopsIcon = new JLabel("\n " + type_operation + " OP/s \n\n" + Double.toString(iops)); iopsIcon.setFont(iopsIcon.getFont().deriveFont(19.0f)); iopsIcon.setForeground(BLUE); iopsIcon.setBackground(WHITE); //Configures the panel NewJFrame.jPanel11.removeAll(); GridLayout layout = new GridLayout(0, 3); NewJFrame.jPanel11.setLayout(layout); NewJFrame.jPanel11.add(throughputIcon); NewJFrame.jPanel11.add(iopsIcon); NewJFrame.jPanel11.revalidate(); NewJFrame.jPanel11.repaint(); }
Example 4
Source File: TaskListTable.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if( getFoldingModel().isGroupRow( row ) ) { // hasFocus = table.isFocusOwner() && isSelected; } Component res = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if( res instanceof JLabel ) { if( value instanceof FoldingTaskListModel.FoldingGroup ) { FoldingTaskListModel.FoldingGroup fg = (FoldingTaskListModel.FoldingGroup)value; JLabel renderer = (JLabel)res; renderer.setText( fg.getGroup().getDisplayName() + " ("+fg.getTaskCount()+")" ); Icon treeIcon = fg.isExpanded() ? openedIcon : closedIcon; renderer.setIcon( treeIcon ); renderer.setToolTipText( fg.getGroup().getDescription() ); renderer.setHorizontalAlignment( JLabel.LEFT ); if( !isSelected ) renderer.setBackground( getBackgroundColor() ); } } return res; }
Example 5
Source File: MagicCollectionIconListRenderer.java From MtgDesktopCompanion with GNU General Public License v3.0 | 6 votes |
@Override public Component getListCellRendererComponent(JList<? extends MagicCollection> list, MagicCollection value, int index,boolean isSelected, boolean cellHasFocus) { if (value != null) { JLabel l = new JLabel(value.getName()); l.setOpaque(true); l.setToolTipText(value.getName()); if (isSelected) { l.setBackground(list.getSelectionBackground()); l.setForeground(list.getSelectionForeground()); } else { l.setBackground(list.getBackground()); l.setForeground(list.getForeground()); } l.setIcon(MTGConstants.ICON_COLLECTION); return l; } return new JLabel(); }
Example 6
Source File: ScaleFactorsTableModel.java From opensim-gui with Apache License 2.0 | 5 votes |
public Component getMeasurementSubCellRenderer(JTable table, BodyScaleFactors scaleFactors, boolean isSelected, boolean hasFocus, int row, int col, int i, int n) { String name; Font font = null; boolean valid = true; if(scaleFactors.useManualScale()) { name = "MANUAL SCALES"; font = boldFont; } else { name = (scaleFactors.measurements[i]==-1) ? ScaleFactorsTableModel.unassignedMeasurement : scaleToolModel.getMeasurementName(scaleFactors.measurements[i]); font = regularFont; if(scaleFactors.measurements[i]!=-1 && scaleToolModel.getMeasurementValue(scaleFactors.measurements[i])==null) valid = false; } // Reset bg/fg colors before calling super.getTableCellRendererComponent() setBackground(null); setForeground(null); JLabel label = (JLabel)super.getTableCellRendererComponent(table,name,isSelected,hasFocus,row,col); intendedBorder = label.getBorder(); if(n==3) label.setBorder(interiorBorders[i]); else label.setBorder(null); label.setHorizontalAlignment(SwingConstants.LEADING); label.setFont(font); // Override bg/fg colors for invalid measurment (most likely it refers to markers which are not available in the model) if(!valid) { if(isSelected) label.setForeground(invalidColor); else label.setBackground(invalidColor); } return label; }
Example 7
Source File: DayChooser.java From javamoney-examples with Apache License 2.0 | 5 votes |
private static void selectLabel(JLabel label) { label.setBackground(HIGHLIGHT_CELL_COLOR); label.setBorder(BORDER_SELECTED); label.setForeground(Color.WHITE); }
Example 8
Source File: PlayersTable.java From freecol with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Player player = (Player)table.getValueAt(row, PlayersTable.PLAYER_COLUMN); final NationType nationType = ((Nation)table.getValueAt(row, PlayersTable.NATION_COLUMN)).getType(); JLabel label; switch (advantages) { case SELECTABLE: return Utility.localizedLabel(Messages.nameKey((player == null) ? nationType : player.getNationType())); case FIXED: label = Utility.localizedLabel(Messages.nameKey(nationType)); break; case NONE: default: label = Utility.localizedLabel("none"); break; } label.setForeground((player != null && player.isReady()) ? Color.GRAY : table.getForeground()); label.setBackground(table.getBackground()); Utility.localizeToolTip(this, StringTemplate .key(advantages.getShortDescriptionKey())); return label; }
Example 9
Source File: Query.java From opt4j with MIT License | 5 votes |
/** * Create a single-line entry box with the specified name, label, default * value, and background color. To control the width of the box, call * setTextWidth() first. * * @param name * The name used to identify the entry (when accessing the * entry). * @param label * The label to attach to the entry. * @param defaultValue * Default value to appear in the entry box. * @param background * The background color. * @param foreground * The foreground color. */ public void addLine(String name, String label, String defaultValue, Color background, Color foreground) { JLabel lbl = new JLabel(label + ": "); lbl.setBackground(_background); JTextField entryBox = new JTextField(defaultValue, _width); entryBox.setBackground(background); entryBox.setForeground(foreground); _addPair(name, lbl, entryBox, entryBox); // Add the listener last so that there is no notification // of the first value. entryBox.addActionListener(new QueryActionListener(name)); // Add a listener for loss of focus. When the entry gains // and then loses focus, listeners are notified of an update, // but only if the value has changed since the last notification. // FIXME: Unfortunately, Java calls this listener some random // time after the window has been closed. It is not even a // a queued event when the window is closed. Thus, we have // a subtle bug where if you enter a value in a line, do not // hit return, and then click on the X to close the window, // the value is restored to the original, and then sometime // later, the focus is lost and the entered value becomes // the value of the parameter. I don't know of any workaround. entryBox.addFocusListener(new QueryFocusListener(name)); }
Example 10
Source File: Query.java From opt4j with MIT License | 5 votes |
/** * Create a choice menu. * * @param name * The name used to identify the entry (when calling get). * @param label * The label to attach to the entry. * @param values * The list of possible choices. * @param defaultChoice * Default choice. * @param editable * True if an arbitrary choice can be entered, in addition to the * choices in values. * @param background * The background color for the editable part. * @param foreground * The foreground color for the editable part. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public void addChoice(String name, String label, String[] values, String defaultChoice, boolean editable, final Color background, final Color foreground) { JLabel lbl = new JLabel(label + ": "); lbl.setBackground(_background); JComboBox combobox = new JComboBox(values); combobox.setEditable(editable); // NOTE: Typical of Swing, the following does not set // the background color. So we have to specify a // custom editor. #$(#&$#(@#!! // combobox.setBackground(background); combobox.setEditor(new BasicComboBoxEditor() { @Override public Component getEditorComponent() { Component result = super.getEditorComponent(); result.setBackground(background); result.setForeground(foreground); return result; } }); combobox.setSelectedItem(defaultChoice); _addPair(name, lbl, combobox, combobox); // Add the listener last so that there is no notification // of the first value. combobox.addItemListener(new QueryItemListener(name)); }
Example 11
Source File: MatchMarkupStatusBatteryRenderer.java From ghidra with Apache License 2.0 | 5 votes |
@Override public Component getTableCellRendererComponent(GTableCellRenderingData data) { // be sure to let our parent perform any initialization needed JLabel renderer = (JLabel) super.getTableCellRendererComponent(data); Object value = data.getValue(); JTable table = data.getTable(); boolean isSelected = data.isSelected(); setText(""); setHorizontalAlignment(CENTER); VTMatch match = (VTMatch) value; VTAssociation association = match.getAssociation(); VTAssociationStatus associationStatus = association.getStatus(); if (!isSelected) { // gray out our background if we are locked-out renderer.setBackground(MatchTableRenderer.getBackgroundColor(association, table, renderer.getBackground())); } if (associationStatus == VTAssociationStatus.ACCEPTED) { VTAssociationMarkupStatus markupStatus = association.getMarkupStatus(); markupStatusIcon.setStatus(markupStatus); setIcon(markupStatusIcon); setToolTipText(HTMLUtilities.toHTML(markupStatus.getDescription())); } else { setIcon(null); } return this; }
Example 12
Source File: PreviewPane.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public PreviewPane(JFileChooser chooser) { chooser.setAccessory(this); chooser.addPropertyChangeListener(this); setLayout(new BorderLayout(5, 5)); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); previewDetails = new JLabel("Preview:"); add(previewDetails, BorderLayout.NORTH); label = new JLabel(); label.setBackground(Color.WHITE); label.setPreferredSize(new Dimension(200, 200)); maxImgWidth = 195; label.setOpaque(false); label.setBorder(BorderFactory.createEtchedBorder()); add(label, BorderLayout.CENTER); }
Example 13
Source File: AutocompletionCellRenderer.java From ghidra with Apache License 2.0 | 5 votes |
@Override public Component getListCellRendererComponent(JList<? extends T> list, T value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); label.setText(owner.getCompletionDisplay(value)); if (label.getText().equals("")) { label.setText(" "); } Font font = owner.getCompletionFont(value, isSelected, cellHasFocus); if (font != null) { label.setFont(font); } Icon icon = owner.getCompletionIcon(value, isSelected, cellHasFocus); if (icon != null) { label.setIcon(icon); } Color fg = owner.getCompletionForeground(value, isSelected, cellHasFocus); if (fg != null) { label.setForeground(fg); } Color bg = owner.getCompletionBackground(value, isSelected, cellHasFocus); if (bg != null) { label.setBackground(bg); } return label; }
Example 14
Source File: GlobalSearchCategoryPanel.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
/** * Init the GUI. * * @param provider * the provider instance, must not be {@code null} */ private void initGUI(final GlobalSearchableGUIProvider provider) { setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); setOpaque(false); setBorder(TOP_BORDER); JLabel i18nName = new JLabel(); i18nName.setBackground(Colors.WINDOW_BACKGROUND); i18nName.setForeground(Color.GRAY); i18nName.setOpaque(true); i18nName.setVerticalAlignment(SwingConstants.TOP); i18nName.setHorizontalAlignment(SwingConstants.LEFT); i18nName.setFont(i18nName.getFont().deriveFont(Font.BOLD)); i18nName.setText(provider.getI18nNameForSearchable()); i18nName.setMinimumSize(I18N_NAME_SIZE); i18nName.setPreferredSize(I18N_NAME_SIZE); i18nName.setMaximumSize(I18N_NAME_SIZE); i18nName.setBorder(CATEGORY_LABEL_EMPTY_BORDER); gbc.gridx = 0; gbc.gridy = 0; gbc.weighty = 1.0d; gbc.fill = GridBagConstraints.VERTICAL; add(i18nName, gbc); contentPanel = new JPanel(); contentPanel.setLayout(new GridBagLayout()); contentPanel.setBorder(DIVIDER_BORDER); contentPanel.setBackground(Colors.WHITE); gbc.gridx = 1; gbc.weightx = 1.0d; gbc.weighty = 1.0d; gbc.fill = GridBagConstraints.BOTH; add(contentPanel, gbc); }
Example 15
Source File: ShipStatRenderer.java From Open-Realms-of-Stars with GNU General Public License v2.0 | 5 votes |
@Override public Component getListCellRendererComponent( final JList<? extends ShipStat> list, final ShipStat value, final int index, final boolean isSelected, final boolean cellHasFocus) { JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus); renderer.setFont(GuiStatics.getFontCubellan()); StringBuilder sb = new StringBuilder(); sb.append(value.getDesign().getName()); sb.append(" - "); sb.append(value.getDesign().getHull().getSize()); if (value.isObsolete()) { sb.append(" Obsoleted"); } else { sb.append(" Cost/Metal: "); sb.append(value.getDesign().getCost()); sb.append("/"); sb.append(value.getDesign().getMetalCost()); } renderer.setText(sb.toString()); if (isSelected) { if (value.isObsolete()) { renderer.setForeground(GuiStatics.COLOR_GREY_TEXT); } else { renderer.setForeground(GuiStatics.COLOR_GREEN_TEXT); } renderer.setBackground(Color.BLACK); } else { if (value.isObsolete()) { renderer.setForeground(GuiStatics.COLOR_GREY_TEXT_DARK); } else { renderer.setForeground(GuiStatics.COLOR_GREEN_TEXT_DARK); } renderer.setBackground(Color.BLACK); } return renderer; }
Example 16
Source File: CapabilityTable.java From arcusplatform with Apache License 2.0 | 4 votes |
protected void renderValue(Component c, AttributeDefinition definition, boolean isSelected) { JLabel label = (JLabel) c; String name = getAttributeName(definition); Object value = getValue(name); if(value == null) { label.setText("Not Set"); label.setFont(getFont().deriveFont(Font.ITALIC)); } else { String text = getValueText(definition, name, value); if(text == null) { label.setText("Invalid"); label.setFont(getFont().deriveFont(Font.ITALIC)); } else { label.setText(text); label.setToolTipText(getValueTooltipText(definition, name, value)); } } if(definition.isWritable()) { label.setForeground(UIManager.getColor("Label.foreground")); } else { label.setForeground(UIManager.getColor("Label.disabledForeground")); } boolean isModified = this.modified.contains(name); boolean isDirty = this.data.isDirty(name); if(isModified && isDirty) { label.setBackground(collisionColor); } else if(isDirty) { label.setBackground(editedColor); } else if(isModified) { label.setBackground(modifiedColor); } else if(isSelected) { label.setBackground(UIManager.getColor("Table.selectionBackground")); } else { label.setBackground(table.getBackground()); } }
Example 17
Source File: DataToolPropsTable.java From osp with GNU General Public License v3.0 | 4 votes |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) { panel.remove(checkbox); panel.remove(plot); int labelCol = dataTable.convertColumnIndexToView(0); int xCol = (labelCol==0) ? 1 : 0; int yCol = (labelCol<2) ? 2 : 1; Color color = (col==xCol) ? DataToolTable.xAxisColor : (col==yCol) ? DataToolTable.yAxisColor : Color.white; panel.setBackground((row!=axisRow) ? Color.white : color); if(value==null) { return panel; } if(value instanceof String) { Component c = getDefaultRenderer(String.class).getTableCellRendererComponent(DataToolPropsTable.this, value, false, false, 0, 0); if(c instanceof JLabel) { JLabel label = (JLabel) c; label.setHorizontalAlignment(SwingConstants.CENTER); label.setBackground(color); label.setBorder(new CellBorder(new Color(240, 240, 240))); return label; } } if(value instanceof WorkingDataset) { WorkingDataset working = (WorkingDataset) value; markerset.setMarkerColor(working.getFillColor(), working.getEdgeColor()); markerset.setMarkerSize(working.getMarkerSize()); markerset.setMarkerShape(working.markerType); lineset.setLineColor(working.getLineColor()); Boolean markerVis = (Boolean) propsModel.getValueAt(markerRow, col); Boolean lineVis = (Boolean) propsModel.getValueAt(lineRow, col); plot.clear(); if(markerVis.booleanValue()) { plot.addDrawable(markerset); } if(lineVis.booleanValue()) { plot.addDrawable(lineset); } panel.add(plot); } else { // value is Boolean if(col==xCol) { return panel; } checkbox.setSelected(((Boolean) value).booleanValue()); checkbox.setEnabled(propsModel.isCellEditable(row, col)); panel.add(checkbox); } panel.setBorder(new CellBorder(new Color(240, 240, 240))); return panel; }
Example 18
Source File: RouteTablePanel.java From openvisualtraceroute with GNU Lesser General Public License v3.0 | 4 votes |
/** * @see javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, * java.lang.Object, boolean, boolean, int, int) */ @Override public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) { final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (c instanceof JLabel) { final JLabel label = (JLabel) c; // bg selection color if (isSelected) { label.setBackground(new Color(200, 200, 255)); } else { // otherwise, alternate bg color if (row % 2 == 0) { label.setBackground(new Color(245, 245, 245)); } else { label.setBackground(new Color(254, 254, 254)); } } final Column col = _indexToColumn.get(column); if (col == Column.COUNTRY_FLAG) { label.setText(""); label.setIcon((ImageIcon) value); } else if (col == Column.WHO_IS) { final JButton button = new JButton("?"); button.setMargin(new Insets(0, 0, 0, 0)); if (Env.INSTANCE.getOs() == OS.win) { button.setBorder(null); } final RoutePoint point = _route.getRoute().get(row); button.setToolTipText(Column.WHO_IS.getLabel()); button.setPreferredSize(new Dimension(Column.WHO_IS.getWidth(), c.getHeight())); button.setEnabled(!_searching && point != null && !point.isUnknown()); return button; } else { if ((col == Column.LATENCY || col == Column.DNS_LOOKUP) && value.equals(0l)) { if (!_dnsLookup && col == Column.DNS_LOOKUP) { label.setText(""); } else { label.setText("<1"); } } } label.setToolTipText(label.getText()); } c.setFont(Env.INSTANCE.getFont()); return c; }
Example 19
Source File: TitleTableCellRenderer.java From Zettelkasten with GNU General Public License v3.0 | 4 votes |
@Override public Component getTableCellRendererComponent( JTable table, Object color, boolean isSelected, boolean hasFocus, int row, int column) { Object value = table.getValueAt(row, 0); int nr = -1; if (value != null) { try { nr = Integer.parseInt(value.toString()); } catch (NumberFormatException e) { } } JLabel returnLabel; if (nr != -1) { // get note if (dataObj.isTopLevelLuhmann(nr)) { returnLabel = this.iconLabelParentLuhmann; } else if (dataObj.findParentlLuhmann(nr, true) != -1) { if (dataObj.hasLuhmannNumbers(nr)) { returnLabel = this.iconLabelMiddleLuhmann; } else { returnLabel = this.iconLabelLastLuhmann; } } else { returnLabel = this.noIconLabel; } } else { returnLabel = this.noIconLabel; } if (isSelected) { returnLabel.setBackground(selectionBackground); } else { returnLabel.setBackground(row % 2 == 0 ? tableRowBackground : tableRowAlternate); } returnLabel.setOpaque(true); return returnLabel; }
Example 20
Source File: ImportModulePanel.java From netbeans with Apache License 2.0 | 4 votes |
/** Creates new form ImportClassPanel. */ @SuppressWarnings("deprecation") public ImportModulePanel(List</*TypeElement*/String> priviledged, List</*TypeElement*/String> denied, Font font, ParserResult info, int position) { this.info = info; this.position = position; createModel(priviledged, denied); initComponents(); setBackground(jList1.getBackground()); if (model.size() > 0) { jList1.setModel(model); setFocusable(false); setNextFocusableComponent(jList1); jScrollPane1.setBackground(jList1.getBackground()); setBackground(jList1.getBackground()); if (font != null) { jList1.setFont(font); } int modelSize = jList1.getModel().getSize(); if (modelSize > 0) { jList1.setSelectedIndex(0); } jList1.setVisibleRowCount(modelSize > 8 ? 8 : modelSize); jList1.setCellRenderer(new Renderer(jList1)); jList1.grabFocus(); } else { remove(jScrollPane1); JLabel nothingFoundJL = new JLabel(NbBundle.getMessage(ImportModulePanel.class, "NoModsFound")); if (font != null) { nothingFoundJL.setFont(font); } nothingFoundJL.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 4, 4, 4)); nothingFoundJL.setEnabled(false); nothingFoundJL.setBackground(jList1.getBackground()); //nothingFoundJL.setOpaque(true); add(nothingFoundJL); } setA11Y(); updatePreview(null); }