Java Code Examples for java.awt.Component#getBackground()

The following examples show how to use java.awt.Component#getBackground() . These examples are extracted from open source projects. 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
private void adaptColorSchemePreviewComponent(ColorScheme colorScheme, Component comp, int index) {

		nameLabel.setText(colorScheme.getName());

		List<ColorRGB> colors = colorScheme.getColors();
		int colorCount = colors.size();
		Color background = comp.getBackground();
		for (int i = 0; i < colorPanels.length; ++i) {

			if (i < colorCount) {
				Color cColor = ColorRGB.convertToColor(colors.get(i));
				colorPanels[i].setBackground(cColor);
			} else {
				colorPanels[i].setBackground(background);
			}

		}

		colorSchemeComponent.setBackground(background);
		colorPanel.setBackground(background);

	}
 
Example 2
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
        boolean hasFocus, int row, int column) {

    setSelected((Boolean) value);

    // the default check box renderer does not use the correct, alternating colors
    // this code is modified from http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6723524
    Component other = (JLabel) table.getDefaultRenderer(String.class).getTableCellRendererComponent(table,
            value, isSelected, hasFocus, row, column);
    java.awt.Color bg = other.getBackground();

    if (isSelected) {
        setForeground(table.getSelectionForeground());
        setBackground(table.getSelectionBackground());
    }
    else {
        setForeground(other.getForeground());
        setBackground(new java.awt.Color(bg.getRed(), bg.getGreen(), bg.getBlue()));
    }

    setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    setOpaque(true);

    return this;
}
 
Example 3
Source Project: jplag   File: TableSorter.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void paintIcon(Component c, Graphics g, int x, int y) {
    Color color = c == null ? Color.GRAY : c.getBackground();             
    // In a compound sort, make each succesive triangle 20% 
    // smaller than the previous one. 
    int dx = (int)(size/2*Math.pow(0.8, priority));
    int dy = descending ? dx : -dx;
    // Align icon (roughly) with font baseline. 
    y = y + 5*size/6 + (descending ? -dy : 0);
    int shift = descending ? 1 : -1;
    g.translate(x, y);

    // Right diagonal. 
    g.setColor(color.darker());
    g.drawLine(dx / 2, dy, 0, 0);
    g.drawLine(dx / 2, dy + shift, 0, shift);
    
    // Left diagonal. 
    g.setColor(color.brighter());
    g.drawLine(dx / 2, dy, dx, 0);
    g.drawLine(dx / 2, dy + shift, dx, shift);
    
    // Horizontal line. 
    if (descending) {
        g.setColor(color.darker().darker());
    } else {
        g.setColor(color.brighter().brighter());
    }
    g.drawLine(dx, 0, 0, 0);

    g.setColor(color);
    g.translate(-x, -y);
}
 
Example 4
Source Project: beautyeye   File: DemoSelectorPanel.java    License: Apache License 2.0 5 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    AbstractButton b = (AbstractButton)c;
    if (b.isSelected()) {
        Color color = c.getBackground();
        g.setColor(Utilities.deriveColorHSB(color, 0, 0, -.20f));
        g.drawLine(x, y, x + width, y);
        g.setColor(Utilities.deriveColorHSB(color, 0, 0, -.10f));
        g.drawLine(x, y + 1, x + width, y + 1);
        g.drawLine(x, y + 2, x, y + height - 2);
        g.setColor(Utilities.deriveColorHSB(color, 0, 0, .24f));
        g.drawLine(x, y + height - 1, x + width, y + height-1);
    }
}
 
Example 5
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Color color = c.getBackground();

    if (origColor != color) {
        origColor = color;
        paintColor = new Color(~origColor.getRGB());
    }

    g.setColor(paintColor);
    BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
}
 
Example 6
Source Project: pdfxtk   File: StyleEditor.java    License: Apache License 2.0 5 votes vote down vote up
Style(Component c) {
     if(c instanceof JLabel) {
hAlign = ((JLabel)c).getHorizontalAlignment();
vAlign = ((JLabel)c).getVerticalAlignment();
     }
     if(c instanceof AbstractButton) {
hAlign = ((AbstractButton)c).getHorizontalAlignment();
vAlign = ((AbstractButton)c).getVerticalAlignment();
     }
     background = c.getBackground();
     foreground = c.getForeground();
     font       = c.getFont();
   }
 
Example 7
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Color color = c.getBackground();

    if (origColor != color) {
        origColor = color;
        paintColor = new Color(~origColor.getRGB());
    }

    g.setColor(paintColor);
    BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
}
 
Example 8
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Color color = c.getBackground();

    if (origColor != color) {
        origColor = color;
        paintColor = new Color(~origColor.getRGB());
    }

    g.setColor(paintColor);
    BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
}
 
Example 9
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Color color = c.getBackground();

    if (origColor != color) {
        origColor = color;
        paintColor = new Color(~origColor.getRGB());
    }

    g.setColor(paintColor);
    BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
}
 
Example 10
Source Project: netbeans   File: GridBagInfoProvider.java    License: Apache License 2.0 5 votes vote down vote up
private static Color deriveEmphColor(Component component) {
    // derive the color for emphasizing from background
    Color backColor = component.getBackground();
    Color emphColor;
    int backBrightness = (30*backColor.getRed()+59*backColor.getGreen()+11*backColor.getBlue())/100;
    if (backBrightness >= 128) {
        emphColor = backColor.darker();
    } else { // brightening a dark area seems visually less notable than darkening a bright area
        emphColor = backColor.brighter().brighter();
    }
    return emphColor;
}
 
Example 11
Source Project: littleluck   File: DemoSelectorPanel.java    License: Apache License 2.0 5 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Color color = c.getBackground();
    // render highlight at top
    g.setColor(Utilities.deriveColorHSB(color, 0, 0, .2f));
    g.drawLine(x, y, x + width, y);
    // render shadow on bottom
    g.setColor(Utilities.deriveColorHSB(color, 0, 0, -.2f));
    g.drawLine(x, y + height - 1, x + width, y + height - 1);
}
 
Example 12
Source Project: binnavi   File: CTableSorter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void paintIcon(final Component c, final Graphics g, final int x, int y) {
  final Color color = c == null ? Color.GRAY : c.getBackground();
  // In a compound sort, make each succesive triangle 20%
  // smaller than the previous one.
  final int dx = (int) ((size / 2) * Math.pow(0.8, priority));
  final int dy = descending ? dx : -dx;
  // Align icon (roughly) with font baseline.
  y = y + ((5 * size) / 6) + (descending ? -dy : 0);
  final int shift = descending ? 1 : -1;
  g.translate(x, y);

  // Right diagonal.
  g.setColor(color.darker());
  g.drawLine(dx / 2, dy, 0, 0);
  g.drawLine(dx / 2, dy + shift, 0, shift);

  // Left diagonal.
  g.setColor(color.brighter());
  g.drawLine(dx / 2, dy, dx, 0);
  g.drawLine(dx / 2, dy + shift, dx, shift);

  // Horizontal line.
  if (descending) {
    g.setColor(color.darker().darker());
  } else {
    g.setColor(color.brighter().brighter());
  }
  g.drawLine(dx, 0, 0, 0);

  g.setColor(color);
  g.translate(-x, -y);
}
 
Example 13
public void paintIcon(Component c, Graphics g, int x, int y) {
  Color backgroundColor = c.getBackground();

  if (backgroundColor != null)
    g.setColor(backgroundColor);
  else g.setColor(Color.white);
  g.fillRect(x, y, 8, 8);
  g.setColor(Color.gray);
  g.drawRect(x, y, 8, 8);
  g.setColor(Color.black);
  g.drawLine(x + 2, y + 4, x + (6), y + 4);
}
 
Example 14
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
	Color color = c == null ? Color.GRAY : c.getBackground();
	// In a compound sort, make each succesive triangle 20%
	// smaller than the previous one.
	int dx = (int) (size / 2 * Math.pow(0.8, priority));
	int dy = descending ? dx : -dx;
	// Align icon (roughly) with font baseline.
	y = y + 5 * size / 6 + (descending ? -dy : 0);
	int shift = descending ? 1 : -1;
	g.translate(x, y);

	// Right diagonal.
	g.setColor(color.darker());
	g.drawLine(dx / 2, dy, 0, 0);
	g.drawLine(dx / 2, dy + shift, 0, shift);

	// Left diagonal.
	g.setColor(color.brighter());
	g.drawLine(dx / 2, dy, dx, 0);
	g.drawLine(dx / 2, dy + shift, dx, shift);

	// Horizontal line.
	if (descending) {
		g.setColor(color.darker().darker());
	} else {
		g.setColor(color.brighter().brighter());
	}
	g.drawLine(dx, 0, 0, 0);

	g.setColor(color);
	g.translate(-x, -y);
}
 
Example 15
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Color color = c.getBackground();

    if (origColor != color) {
        origColor = color;
        paintColor = new Color(~origColor.getRGB());
    }

    g.setColor(paintColor);
    BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
}
 
Example 16
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Color color = c.getBackground();

    if (origColor != color) {
        origColor = color;
        paintColor = new Color(~origColor.getRGB());
    }

    g.setColor(paintColor);
    BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
}
 
Example 17
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Color color = c.getBackground();

    if (origColor != color) {
        origColor = color;
        paintColor = new Color(~origColor.getRGB());
    }

    g.setColor(paintColor);
    BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
}
 
Example 18
Source Project: pdfxtk   File: StyleEditor.java    License: Apache License 2.0 5 votes vote down vote up
public void preset(Component c, boolean dontColorize) {
  Color svb = getCurrStyle().background;
  Color svf = getCurrStyle().foreground;
  if(dontColorize) {
    getCurrStyle().background = c.getBackground();
    getCurrStyle().foreground = c.getForeground();      
  }
  setStyle(c, getCurrStyle());
  getCurrStyle().background = svb;
  getCurrStyle().foreground = svf;
}
 
Example 19
Source Project: osp   File: DataToolTable.java    License: GNU General Public License v3.0 4 votes vote down vote up
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;
}
 
Example 20
public FadeComponent(Component jComponent) {
	this.jComponent = jComponent;
	this.color = jComponent.getBackground();
}