javax.swing.JComponent#setBackground ( )源码实例Demo

下面列出了javax.swing.JComponent#setBackground ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: RendererPropertyDisplayer.java
protected void prepareRenderer(JComponent comp) {
    comp.setBackground(getBackground());
    comp.setForeground(getForeground());
    comp.setBounds(0, 0, getWidth(), getHeight());

    JComponent innermost;

    if ((innermost = findInnermostRenderer(comp)) instanceof JComboBox) {
        if (comp.getLayout() != null) {
            comp.getLayout().layoutContainer(comp);
        }
    }

    if (!isTableUI() && ((InplaceEditor) comp).supportsTextEntry()) {
        innermost.setBackground(PropUtils.getTextFieldBackground());
        innermost.setForeground(PropUtils.getTextFieldForeground());
    }
}
 
源代码2 项目: Raccoon   文件: ListView.java
public void add(JComponent comp) {
	comp.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY, 2));
	comp.getInsets().bottom = 10;
	comp.getInsets().top = 10;
	comp.getInsets().right = 10;
	comp.getInsets().left = 10;
	if (zebra) {
		comp.setBackground(Color.GRAY);
	}
	else {
		comp.setBackground(Color.LIGHT_GRAY);
	}
	zebra = !zebra;
	gbc.gridy++;
	super.add(comp, gbc);
}
 
源代码3 项目: xdm   文件: XDMButtonUI.java
@Override
public void installUI(JComponent c) {
	super.installUI(c);
	if (c instanceof JButton) {
		JButton btn = (JButton) c;
		if (!(c instanceof CustomButton)) {
			c.setForeground(Color.WHITE);
			c.setBackground(ColorResource.getButtonBackColor());
			btn.setBorderPainted(false);
		}
	}
}
 
源代码4 项目: material-ui-swing   文件: MaterialToolBarUI.java
@Override
public void uninstallUI(JComponent c) {

	c.setFont (null);
	c.setBackground (null);
	c.setForeground (null);
	c.setBorder (null);
	c.setCursor(null);

	this.dockingColor = null;
	this.floatingColor = null;
	super.uninstallUI(c);
}
 
源代码5 项目: visualvm   文件: ProfilerTreeTable.java
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    setValue(value, row); // NOTE: should use table.convertRowIndexToModel(row)
    JComponent comp = getComponent();
    comp.setOpaque(false);
    if (tree != null) {
        comp.setForeground(tree.getForeground());
        comp.setBackground(tree.getBackground());
    }
    return comp;
}
 
源代码6 项目: Astrosoft   文件: UIUtil.java
public static void setPanelBackground(JComponent panel, Color color) {
	if (panel!=null){
		panel.setBackground(color);
		for (Component c : panel.getComponents()) {
			if (c instanceof JPanel) {
				setPanelBackground((JPanel) c, color);
			}
		}
	}	
}
 
源代码7 项目: jdal   文件: BackgroundErrorProcessor.java
/**
 * {@inheritDoc}
 */
public void reset() {
	for (JComponent c : colorMap.keySet()) {
		c.setBackground(colorMap.get(c));
		c.setToolTipText(null);
	}
	colorMap.clear();
}
 
源代码8 项目: jmeter-plugins   文件: IntegerInputVerifier.java
/**
 * Verifies the input with the side effect that the background color of {@code input} to {@code background} if
 * returns {@code true}, or {@code warningBackground} otherwise
 *
 * @param input component
 * @return if input is valid
 */
public boolean shouldYieldFocus(JComponent input) {
    boolean isValidInput = verify(input);
    if (isValidInput) {
        input.setBackground(background);
    } else {
        input.setBackground(warningBackground);
    }
    return isValidInput;
}
 
源代码9 项目: hottub   文件: DiagramScene.java
public DiagramScene(Action[] actions, DiagramViewModel model) {
    this.actions = actions;
    selectedWidgets = new ArrayList<FigureWidget>();
    content = new InstanceContent();
    lookup = new AbstractLookup(content);
    this.setCheckClipping(true);
    this.getInputBindings().setZoomActionModifiers(0);

    JComponent comp = this.createView();
    comp.setDoubleBuffered(true);
    comp.setBackground(Color.WHITE);
    comp.setOpaque(true);

    this.setBackground(Color.WHITE);
    this.setOpaque(true);
    scrollPane = new JScrollPane(comp);
    scrollPane.setBackground(Color.WHITE);
    scrollPane.getVerticalScrollBar().setUnitIncrement(SCROLL_UNIT_INCREMENT);
    scrollPane.getVerticalScrollBar().setBlockIncrement(SCROLL_BLOCK_INCREMENT);
    scrollPane.getHorizontalScrollBar().setUnitIncrement(SCROLL_UNIT_INCREMENT);
    scrollPane.getHorizontalScrollBar().setBlockIncrement(SCROLL_BLOCK_INCREMENT);
    scrollPane.getViewport().addChangeListener(scrollChangeListener);
    hoverAction = this.createWidgetHoverAction();

    blockLayer = new LayerWidget(this);
    this.addChild(blockLayer);

    startLayer = new LayerWidget(this);
    this.addChild(startLayer);
    // TODO: String startLabelString = "Loading graph with " + originalDiagram.getFigures().size() + " figures and " + originalDiagram.getConnections().size() + " connections...";
    String startLabelString = "";
    LabelWidget w = new LabelWidget(this, startLabelString);
    scrollChangeListener.register(w, new Point(10, 10));
    w.setAlignment(LabelWidget.Alignment.CENTER);
    startLabel = w;
    startLayer.addChild(w);

    mainLayer = new LayerWidget(this);
    this.addChild(mainLayer);

    topLeft = new Widget(this);
    topLeft.setPreferredLocation(new Point(-BORDER_SIZE, -BORDER_SIZE));
    this.addChild(topLeft);


    bottomRight = new Widget(this);
    bottomRight.setPreferredLocation(new Point(-BORDER_SIZE, -BORDER_SIZE));
    this.addChild(bottomRight);

    slotLayer = new LayerWidget(this);
    this.addChild(slotLayer);

    connectionLayer = new LayerWidget(this);
    this.addChild(connectionLayer);

    LayerWidget selectionLayer = new LayerWidget(this);
    this.addChild(selectionLayer);

    this.setLayout(LayoutFactory.createAbsoluteLayout());

    this.getActions().addAction(hoverAction);
    zoomAction = new BoundedZoomAction(1.1, false);
    zoomAction.setMaxFactor(ZOOM_MAX_FACTOR);
    zoomAction.setMinFactor(ZOOM_MIN_FACTOR);
    this.getActions().addAction(ActionFactory.createMouseCenteredZoomAction(1.1));
    panAction = new ExtendedPanAction();
    this.getActions().addAction(panAction);
    this.getActions().addAction(ActionFactory.createPopupMenuAction(popupMenuProvider));

    LayerWidget selectLayer = new LayerWidget(this);
    this.addChild(selectLayer);
    this.getActions().addAction(ActionFactory.createRectangularSelectAction(rectangularSelectDecorator, selectLayer, rectangularSelectProvider));

    blockWidgets = new HashMap<InputBlock, BlockWidget>();

    boolean b = this.getUndoRedoEnabled();
    this.setUndoRedoEnabled(false);
    this.setNewModel(model);
    this.setUndoRedoEnabled(b);
}
 
源代码10 项目: ET_Redux   文件: AbstractRatiosDataView.java
/**
 *
 * @param c
 */
protected final void setOpaqueWithLightGray(JComponent c) {
    c.setOpaque(true);
    c.setBackground(ReduxConstants.dataModelGray);
}
 
源代码11 项目: openjdk-jdk8u-backup   文件: DiagramScene.java
public DiagramScene(Action[] actions, DiagramViewModel model) {
    this.actions = actions;
    selectedWidgets = new ArrayList<FigureWidget>();
    content = new InstanceContent();
    lookup = new AbstractLookup(content);
    this.setCheckClipping(true);
    this.getInputBindings().setZoomActionModifiers(0);

    JComponent comp = this.createView();
    comp.setDoubleBuffered(true);
    comp.setBackground(Color.WHITE);
    comp.setOpaque(true);

    this.setBackground(Color.WHITE);
    this.setOpaque(true);
    scrollPane = new JScrollPane(comp);
    scrollPane.setBackground(Color.WHITE);
    scrollPane.getVerticalScrollBar().setUnitIncrement(SCROLL_UNIT_INCREMENT);
    scrollPane.getVerticalScrollBar().setBlockIncrement(SCROLL_BLOCK_INCREMENT);
    scrollPane.getHorizontalScrollBar().setUnitIncrement(SCROLL_UNIT_INCREMENT);
    scrollPane.getHorizontalScrollBar().setBlockIncrement(SCROLL_BLOCK_INCREMENT);
    scrollPane.getViewport().addChangeListener(scrollChangeListener);
    hoverAction = this.createWidgetHoverAction();

    blockLayer = new LayerWidget(this);
    this.addChild(blockLayer);

    startLayer = new LayerWidget(this);
    this.addChild(startLayer);
    // TODO: String startLabelString = "Loading graph with " + originalDiagram.getFigures().size() + " figures and " + originalDiagram.getConnections().size() + " connections...";
    String startLabelString = "";
    LabelWidget w = new LabelWidget(this, startLabelString);
    scrollChangeListener.register(w, new Point(10, 10));
    w.setAlignment(LabelWidget.Alignment.CENTER);
    startLabel = w;
    startLayer.addChild(w);

    mainLayer = new LayerWidget(this);
    this.addChild(mainLayer);

    topLeft = new Widget(this);
    topLeft.setPreferredLocation(new Point(-BORDER_SIZE, -BORDER_SIZE));
    this.addChild(topLeft);


    bottomRight = new Widget(this);
    bottomRight.setPreferredLocation(new Point(-BORDER_SIZE, -BORDER_SIZE));
    this.addChild(bottomRight);

    slotLayer = new LayerWidget(this);
    this.addChild(slotLayer);

    connectionLayer = new LayerWidget(this);
    this.addChild(connectionLayer);

    LayerWidget selectionLayer = new LayerWidget(this);
    this.addChild(selectionLayer);

    this.setLayout(LayoutFactory.createAbsoluteLayout());

    this.getActions().addAction(hoverAction);
    zoomAction = new BoundedZoomAction(1.1, false);
    zoomAction.setMaxFactor(ZOOM_MAX_FACTOR);
    zoomAction.setMinFactor(ZOOM_MIN_FACTOR);
    this.getActions().addAction(ActionFactory.createMouseCenteredZoomAction(1.1));
    panAction = new ExtendedPanAction();
    this.getActions().addAction(panAction);
    this.getActions().addAction(ActionFactory.createPopupMenuAction(popupMenuProvider));

    LayerWidget selectLayer = new LayerWidget(this);
    this.addChild(selectLayer);
    this.getActions().addAction(ActionFactory.createRectangularSelectAction(rectangularSelectDecorator, selectLayer, rectangularSelectProvider));

    blockWidgets = new HashMap<InputBlock, BlockWidget>();

    boolean b = this.getUndoRedoEnabled();
    this.setUndoRedoEnabled(false);
    this.setNewModel(model);
    this.setUndoRedoEnabled(b);
}
 
源代码12 项目: openjdk-jdk9   文件: CheckAttributedTree.java
/** Set the background on a component. */
private JComponent setBackground(JComponent comp, Color c) {
    comp.setOpaque(true);
    comp.setBackground(c);
    return comp;
}
 
源代码13 项目: TencentKona-8   文件: CheckAttributedTree.java
/** Set the background on a component. */
private JComponent setBackground(JComponent comp, Color c) {
    comp.setOpaque(true);
    comp.setBackground(c);
    return comp;
}
 
源代码14 项目: jdk8u60   文件: DiagramScene.java
public DiagramScene(Action[] actions, DiagramViewModel model) {
    this.actions = actions;
    selectedWidgets = new ArrayList<FigureWidget>();
    content = new InstanceContent();
    lookup = new AbstractLookup(content);
    this.setCheckClipping(true);
    this.getInputBindings().setZoomActionModifiers(0);

    JComponent comp = this.createView();
    comp.setDoubleBuffered(true);
    comp.setBackground(Color.WHITE);
    comp.setOpaque(true);

    this.setBackground(Color.WHITE);
    this.setOpaque(true);
    scrollPane = new JScrollPane(comp);
    scrollPane.setBackground(Color.WHITE);
    scrollPane.getVerticalScrollBar().setUnitIncrement(SCROLL_UNIT_INCREMENT);
    scrollPane.getVerticalScrollBar().setBlockIncrement(SCROLL_BLOCK_INCREMENT);
    scrollPane.getHorizontalScrollBar().setUnitIncrement(SCROLL_UNIT_INCREMENT);
    scrollPane.getHorizontalScrollBar().setBlockIncrement(SCROLL_BLOCK_INCREMENT);
    scrollPane.getViewport().addChangeListener(scrollChangeListener);
    hoverAction = this.createWidgetHoverAction();

    blockLayer = new LayerWidget(this);
    this.addChild(blockLayer);

    startLayer = new LayerWidget(this);
    this.addChild(startLayer);
    // TODO: String startLabelString = "Loading graph with " + originalDiagram.getFigures().size() + " figures and " + originalDiagram.getConnections().size() + " connections...";
    String startLabelString = "";
    LabelWidget w = new LabelWidget(this, startLabelString);
    scrollChangeListener.register(w, new Point(10, 10));
    w.setAlignment(LabelWidget.Alignment.CENTER);
    startLabel = w;
    startLayer.addChild(w);

    mainLayer = new LayerWidget(this);
    this.addChild(mainLayer);

    topLeft = new Widget(this);
    topLeft.setPreferredLocation(new Point(-BORDER_SIZE, -BORDER_SIZE));
    this.addChild(topLeft);


    bottomRight = new Widget(this);
    bottomRight.setPreferredLocation(new Point(-BORDER_SIZE, -BORDER_SIZE));
    this.addChild(bottomRight);

    slotLayer = new LayerWidget(this);
    this.addChild(slotLayer);

    connectionLayer = new LayerWidget(this);
    this.addChild(connectionLayer);

    LayerWidget selectionLayer = new LayerWidget(this);
    this.addChild(selectionLayer);

    this.setLayout(LayoutFactory.createAbsoluteLayout());

    this.getActions().addAction(hoverAction);
    zoomAction = new BoundedZoomAction(1.1, false);
    zoomAction.setMaxFactor(ZOOM_MAX_FACTOR);
    zoomAction.setMinFactor(ZOOM_MIN_FACTOR);
    this.getActions().addAction(ActionFactory.createMouseCenteredZoomAction(1.1));
    panAction = new ExtendedPanAction();
    this.getActions().addAction(panAction);
    this.getActions().addAction(ActionFactory.createPopupMenuAction(popupMenuProvider));

    LayerWidget selectLayer = new LayerWidget(this);
    this.addChild(selectLayer);
    this.getActions().addAction(ActionFactory.createRectangularSelectAction(rectangularSelectDecorator, selectLayer, rectangularSelectProvider));

    blockWidgets = new HashMap<InputBlock, BlockWidget>();

    boolean b = this.getUndoRedoEnabled();
    this.setUndoRedoEnabled(false);
    this.setNewModel(model);
    this.setUndoRedoEnabled(b);
}
 
源代码15 项目: openjdk-jdk9   文件: TreePosTest.java
/** Set the background on a component. */
private JComponent setBackground(JComponent comp, Color c) {
    comp.setOpaque(true);
    comp.setBackground(c);
    return comp;
}
 
源代码16 项目: hottub   文件: CheckAttributedTree.java
/** Set the background on a component. */
private JComponent setBackground(JComponent comp, Color c) {
    comp.setOpaque(true);
    comp.setBackground(c);
    return comp;
}
 
源代码17 项目: stendhal   文件: StyledSeparatorUI.java
@Override
public void installUI(JComponent separator) {
	super.installUI(separator);
	separator.setBackground(style.getHighLightColor());
	separator.setForeground(style.getShadowColor());
}
 
源代码18 项目: netbeans   文件: SheetTable.java
/** Paint the expandable sets.  These are painted double width,
 *  across the entire width of the table. */
private void paintExpandableSets(Graphics g) {
    int start = 0;
    int end = getRowCount();

    Insets ins = getInsets();

    boolean canBeSelected = isKnownComponent(
            KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner()
        );

    for (int i = 0; i < end; i++) {
        int idx = start + i;
        Object value = getValueAt(idx, 0);

        if (value instanceof PropertySet) {
            Rectangle r = getCellRect(idx, 0, false);
            r.x = ins.left;
            r.width = getWidth() - (ins.left + ins.right);

            if (g.hitClip(r.x, r.y, r.width, r.height)) {
                PropertySet ps = (PropertySet) value;

                String txt = ps.getHtmlDisplayName();
                boolean isHtml = txt != null;

                if (!isHtml) {
                    txt = ps.getDisplayName();
                }

                if (htmlrenderer == null) {
                    htmlrenderer = HtmlRenderer.createRenderer();
                }

                JComponent painter = (JComponent) htmlrenderer.getTableCellRendererComponent(
                        this, txt, false, false, idx, 0
                    );

                htmlrenderer.setHtml(isHtml);
                htmlrenderer.setParentFocused(true);

                htmlrenderer.setIconTextGap(2);

                htmlrenderer.setIcon(
                    getPropertySetModel().isExpanded(ps) ? PropUtils.getExpandedIcon() : PropUtils.getCollapsedIcon()
                );

                boolean selected = canBeSelected && (getSelectedRow() == idx);

                if (!selected) {
                    painter.setBackground(PropUtils.getSetRendererColor());
                    painter.setForeground(PropUtils.getSetForegroundColor());
                } else {
                    painter.setBackground(PropUtils.getSelectedSetRendererColor());
                    painter.setForeground(PropUtils.getSelectedSetForegroundColor());
                }

                if( PropUtils.isAqua ) {
                    painter.setOpaque(false);
                    Graphics2D g2d = (Graphics2D) g;
                    Paint oldPaint = g2d.getPaint();
                    g2d.setPaint( new GradientPaint(r.x,r.y, Color.white, r.x, r.y+r.height/2, painter.getBackground()) );
                    g2d.fillRect(r.x, r.y, r.width, r.height);
                    g2d.setPaint(oldPaint);
                } else {
                    painter.setOpaque(true);
                }

                paintComponent(g, painter, r.x, r.y, r.width, r.height);
            }
        }
    }
}
 
源代码19 项目: netbeans   文件: Coloring.java
/** Apply this coloring to component colors/font.
* The underline and strikeThrough line colors have no effect here.
*/
public void apply(JComponent c) {
    // Possibly change font
    if (font != null) {
        if (fontMode == FONT_MODE_DEFAULT) {
            c.setFont(font);

        } else { // non-default font-mode
            Font origFont = c.getFont();
            if (origFont != null) {
                synchronized (cacheLock) {
                    Font f = (Font)fontAndForeColorCache.get(origFont);
                    if (f == null) {
                        f = modifyFont(origFont);
                        fontAndForeColorCache.put(origFont, f);
                    }
                    c.setFont(f);
                }
            }
        }
    }

    // Possibly change fore-color
    if (foreColor != null) {
        if (!hasAlpha(foreColor)) {
            c.setForeground(foreColor);

        } else { // non-default fore color-mode
            Color origForeColor = c.getForeground();
            if (origForeColor != null) {
                synchronized (cacheLock) {
                    Color fc = (Color)fontAndForeColorCache.get(origForeColor);
                    if (fc == null) {
                        fc = modifyForeColor(origForeColor);
                        fontAndForeColorCache.put(origForeColor, fc);
                    }
                    c.setForeground(fc);
                }
            }
        }
    }

    // Possibly change back-color
    if (backColor != null) {
        if (!hasAlpha(backColor)) {
            c.setBackground(backColor);

        } else { // non-default back color-mode
            Color origBackColor = c.getBackground();
            if (origBackColor != null) {
                synchronized (cacheLock) {
                    Color bc = (Color)backColorCache.get(origBackColor);
                    if (bc == null) {
                        bc = modifyBackColor(origBackColor);
                        backColorCache.put(origBackColor, bc);
                    }
                    c.setBackground(bc);
                }
            }
        }
    }
}
 
源代码20 项目: osp   文件: DataToolTable.java
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
  // value is data column name
  String realname = (value==null) ? "" : value.toString(); //$NON-NLS-1$
  String name = realname;
  if (OSPRuntime.isMac()) {
  	name = TeXParser.removeSubscripting(name);
  }
  Component c = renderer.getTableCellRendererComponent(table, name, isSelected, hasFocus, row, col);
  if (headerFont==null) headerFont = c.getFont();
  int labelCol = convertColumnIndexToView(0);
  int xCol = (labelCol==0) ? 1 : 0;
  int yCol = (labelCol<2) ? 2 : 1;
  if(unselectedBG==null) {
    unselectedBG = c.getBackground();
  }
  // backup color in case c has none
  if(unselectedBG==null) {
    unselectedBG = javax.swing.UIManager.getColor("Panel.background"); //$NON-NLS-1$
  }
  rowBG = dataToolTab.plot.getBackground();
  Color bgColor = (col==xCol)? DataToolTable.xAxisColor: 
  		(col==yCol)? DataToolTable.yAxisColor: rowBG;
  if(!(c instanceof JComponent)) {
    return c;
  }
  JComponent comp = (JComponent) c;
  
  java.awt.Dimension dim = comp.getPreferredSize();
  dim.height += 1;
  dim.height = Math.max(getRowHeight()+2, dim.height);
  panel.setPreferredSize(dim);
  javax.swing.border.Border border = comp.getBorder();
  if(border instanceof javax.swing.border.EmptyBorder) {
    border = BorderFactory.createLineBorder(Color.LIGHT_GRAY);
  }
  panel.setBorder(border);
  
  // determine font: italics if undeletable, bold if sorted column
  Font font;
  Dataset data = getDataset(realname);
  if(!dataToolTab.isDeletable(data)) {
    font = getSortedColumn()!=convertColumnIndexToModel(col)? 
    		headerFont.deriveFont(Font.PLAIN+Font.ITALIC) : headerFont.deriveFont(Font.BOLD+Font.ITALIC);
  } else {
    font = getSortedColumn()!=convertColumnIndexToModel(col)? 
    		headerFont.deriveFont(Font.PLAIN) : headerFont.deriveFont(Font.BOLD);
  }
  int[] cols = getSelectedColumns();
  boolean selected = false;
  for(int i = 0; i<cols.length; i++) {
    selected = selected||(cols[i]==col);
  }
  selected = selected&&(convertColumnIndexToModel(col)>0);
  bgColor = selected? selectedHeaderBG: bgColor;
  
  // special case: textline doesn't work on OSX
  if (OSPRuntime.isMac()) {
    comp.setFont(font);
    comp.setBackground(bgColor);
    comp.setForeground(selected ? selectedHeaderFG : comp.getForeground());
    if (comp instanceof JLabel) {
    	((JLabel)comp).setHorizontalAlignment(SwingConstants.CENTER);
    }
    return comp;
  }

  textLine.setText(name);
  textLine.setFont(font);
  textLine.setColor(selected ? selectedHeaderFG : comp.getForeground());
  textLine.setBackground(bgColor);
  panel.setBackground(bgColor);
  return panel;
}