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

The following examples show how to use java.awt.Component#getBackground() . 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: ChartSummaryPanel.java    From nmonvisualizer with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: ColorSchemeComboBoxRenderer.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
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 3
Source File: CTableSorter.java    From binnavi with 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 4
Source File: StyleEditor.java    From pdfxtk with 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 5
Source File: WindowsBorders.java    From openjdk-8 with GNU General Public License v2.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();

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

    g.setColor(paintColor);
    BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
}
 
Example 6
Source File: WindowsBorders.java    From openjdk-8-source with GNU General Public License v2.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();

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

    g.setColor(paintColor);
    BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
}
 
Example 7
Source File: WindowsBorders.java    From hottub with GNU General Public License v2.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();

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

    g.setColor(paintColor);
    BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
}
 
Example 8
Source File: TableSorter.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@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 9
Source File: PropertySheetTable.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
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 10
Source File: TableSorter.java    From jplag with 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 11
Source File: DemoSelectorPanel.java    From littleluck with 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 File: GridBagInfoProvider.java    From netbeans with 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 13
Source File: WindowsBorders.java    From openjdk-jdk8u with GNU General Public License v2.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();

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

    g.setColor(paintColor);
    BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
}
 
Example 14
Source File: WindowsBorders.java    From jdk8u_jdk with GNU General Public License v2.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();

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

    g.setColor(paintColor);
    BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
}
 
Example 15
Source File: WindowsBorders.java    From jdk8u60 with GNU General Public License v2.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();

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

    g.setColor(paintColor);
    BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
}
 
Example 16
Source File: StyleEditor.java    From pdfxtk with 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 17
Source File: WindowsBorders.java    From dragonwell8_jdk with GNU General Public License v2.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();

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

    g.setColor(paintColor);
    BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
}
 
Example 18
Source File: DemoSelectorPanel.java    From beautyeye with 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 19
Source File: DataToolTable.java    From osp with 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
Source File: FilterPanel.java    From jeveassets with GNU General Public License v2.0 4 votes vote down vote up
public FadeComponent(Component jComponent) {
	this.jComponent = jComponent;
	this.color = jComponent.getBackground();
}