List of usage examples for java.awt Component setForeground
public void setForeground(Color c)
From source file:Main.java
/** * Sets the foreground for an entire component hierarchy to the specified * color./*ww w .ja v a 2 s.co m*/ * * @param c * the starting component * @param color * the color to set */ public static void setComponentTreeForeground(Component c, Color color) { c.setForeground(color); Component[] children = getChildren(c); if (children != null) { for (int i = 0; i < children.length; i++) { setComponentTreeForeground(children[i], color); } } }
From source file:Main.java
public static void setColor_r(Component c, Color bg, Color fg) { if (bg != null) { c.setBackground(bg);/*from ww w . ja va 2 s . c om*/ } if (fg != null) { c.setForeground(fg); } if (c instanceof Container) { Component[] comps = ((Container) c).getComponents(); if (comps.length > 0) { for (Component comp : comps) { setColor_r(comp, bg, fg); } } } }
From source file:Main.java
private static void setForegroundOrBackgroundDeep(final boolean doForeground, Component component, Color color, Class[] excludedClasses, boolean processContentsOfExcludedContainers) { // If this component one that should be excluded? boolean excluded = false; if (excludedClasses != null) { for (int i = 0; i < excludedClasses.length && !excluded; i++) { if (excludedClasses[i].isInstance(component)) { excluded = true;//from www . j a va2 s .c o m } } } // If not exluded, set the component's foreground or background. if (!excluded) { if (doForeground) { component.setForeground(color); } else { component.setBackground(color); } } // Recursively process the contents of containers. if ((!excluded || processContentsOfExcludedContainers) && (component instanceof Container)) { Container container = (Container) component; Component[] children = container.getComponents(); if (children != null) { for (int i = 0; i < children.length; i++) { setForegroundOrBackgroundDeep(doForeground, children[i], color, excludedClasses, processContentsOfExcludedContainers); } } } }
From source file:MultiLineLabel.java
public void setForeground(Color col) { this.col = col; Component[] components = this.getComponents(); for (int i = 0; i < components.length; i++) { Component component = components[i]; component.setForeground(col); }/*from w ww . j a v a2 s . c om*/ }
From source file:EvenOddRenderer.java
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component renderer = DEFAULT_RENDERER.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);//ww w . j a v a 2 s.c o m Color foreground, background; if (isSelected) { foreground = Color.YELLOW; background = Color.GREEN; } else { if (row % 2 == 0) { foreground = Color.BLUE; background = Color.WHITE; } else { foreground = Color.WHITE; background = Color.BLUE; } } renderer.setForeground(foreground); renderer.setBackground(background); return renderer; }
From source file:RendererSample.java
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component renderer = DEFAULT_RENDERER.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);//from www . ja v a2 s. c om ((JLabel) renderer).setOpaque(true); Color foreground, background; if (isSelected) { foreground = Color.yellow; background = Color.green; } else { if (row % 2 == 0) { foreground = Color.blue; background = Color.white; } else { foreground = Color.white; background = Color.blue; } } renderer.setForeground(foreground); renderer.setBackground(background); return renderer; }
From source file:ecosim.gui.SummaryPane.java
/** * Private method to build the table pane. * * @return A JLayeredPane containing the table pane. *//*from w w w.j av a 2s . c o m*/ private JLayeredPane makeTablePane() { String[] columnNames = { "", "Estimate", "Hillclimbing", "Low", "High" }; Integer[] columnWidths = { 250, 60, 60, 60, 60 }; Object[][] rowData = { { "Number of putative ecotypes (npop)", null, null, null, null }, { "Rate of ecotype formation (omega)", null, null, null, null }, { "Rate of periodic selection (sigma)", null, null, null, null } }; final JLayeredPane pane = new JLayeredPane(); final JTable table = new JTable(rowData, columnNames) { public boolean isCellEditable(int row, int column) { return false; } }; final JTableHeader header = table.getTableHeader(); pane.setLayout(new BorderLayout()); header.setReorderingAllowed(false); TableColumnModel cm = table.getColumnModel(); for (int i = 0; i < columnWidths.length; i++) { TableColumn column = cm.getColumn(i); column.setMinWidth(columnWidths[i]); if (i == 0) { column.setCellRenderer(new DefaultTableCellRenderer() { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); cell.setBackground(header.getBackground()); cell.setForeground(header.getForeground()); return cell; } }); } } pane.add(table.getTableHeader(), "North"); pane.add(table, "Center"); // Watch for changes to the Summary object. summary.addObserver(new Observer() { public void update(Observable o, Object obj) { Summary s = (Summary) obj; ParameterEstimate estimate = s.getEstimate(); ParameterSet hillclimbing = s.getHillclimbing(); ParameterSet[] ci = s.getConfidenceInterval(); if (estimate != null) { ParameterSet e = estimate.getResult(); table.setValueAt(e.getNpop(), 0, 1); table.setValueAt(String.format("%.4f", e.getOmega()), 1, 1); table.setValueAt(String.format("%.4f", e.getSigma()), 2, 1); } if (hillclimbing != null) { table.setValueAt(hillclimbing.getNpop(), 0, 2); table.setValueAt(String.format("%.4f", hillclimbing.getOmega()), 1, 2); table.setValueAt(String.format("%.4f", hillclimbing.getSigma()), 2, 2); } if (ci[0].getNpop() != null) { table.setValueAt(ci[0].getNpop(), 0, 3); table.setValueAt(ci[1].getNpop(), 0, 4); } if (ci[1].getOmega() != null) { table.setValueAt(String.format("%.4f", ci[0].getOmega()), 1, 3); String fmt = "%.4f"; if (ci[1].getOmega() > 10.0D) { fmt = "%.1f"; } else if (ci[1].getOmega() > 1.0D) { fmt = "%.2f"; } table.setValueAt(String.format(fmt, ci[1].getOmega()), 1, 4); } if (ci[1].getSigma() != null) { table.setValueAt(String.format("%.4f", ci[0].getSigma()), 2, 3); if (ci[1].getSigma() > 100.0D - MasterVariables.EPSILON) { table.setValueAt("100", 2, 4); } else { String fmt = "%.4f"; if (ci[1].getSigma() > 10.0D) { fmt = "%.1f"; } else if (ci[1].getSigma() > 1.0D) { fmt = "%.2f"; } table.setValueAt(String.format(fmt, ci[1].getSigma()), 2, 4); } } pane.repaint(); } }); return pane; }
From source file:com.moneydance.modules.features.importlist.table.HeaderRenderer.java
@Override public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) { Component component = this.defaultHeaderTableCellRenderer.getTableCellRendererComponent(table, value, hasFocus, hasFocus, row, column); if (component instanceof JComponent) { JComponent jComponent = (JComponent) component; jComponent.setBorder(new EmptyBorder(1, 1, 1, 1)); jComponent.setOpaque(false);/*from w w w.j a v a 2 s .co m*/ if (jComponent instanceof JLabel) { JLabel jLabel = (JLabel) jComponent; jLabel.setHorizontalAlignment(SwingConstants.LEFT); } } component.setFont(Preferences.getHeaderFont()); component.setForeground(Preferences.getHeaderForeground()); component.setSize( new Dimension(component.getWidth(), Helper.INSTANCE.getPreferences().getHeaderRowHeight())); component.setMinimumSize( new Dimension(component.getWidth(), Helper.INSTANCE.getPreferences().getHeaderRowHeight())); component.setPreferredSize( new Dimension(component.getWidth(), Helper.INSTANCE.getPreferences().getHeaderRowHeight())); component.setMaximumSize( new Dimension(component.getWidth(), Helper.INSTANCE.getPreferences().getHeaderRowHeight())); return component; }
From source file:hermes.browser.components.WatchTable.java
/** * Rows are: Color.RED if an alert level has been breached. Color.ORANGE if * an exception has occured gathering the data *//*from ww w.j a v a2 s .c om*/ public Component prepareRenderer(TableCellRenderer renderer, int y, int x) { final Component rval = super.prepareRenderer(renderer, y, x); final int originalY = y; y = getActualRowAt(y); final WatchInfo info = watchModel.getRow(y); Component c = null; /* * I don't understand this bit - unless I get the actual renderer when the * component is an ExpandablePanel the first column shades incorrectly. */ if (rval instanceof ExpandablePanel) { ExpandablePanel ep = (ExpandablePanel) rval; c = ep.getActualRenderer(); } else { c = rval; } boolean previousInAlert = info.isInAlert(); if (info != null) { if (info.getE() != null) { info.setInAlert(true); c.setBackground(new Color(255, 255, 153)); c.setForeground(Color.BLACK); } else if (info.getDepthAlert() != 0 && (info.getDepth() > info.getDepthAlert())) { info.setInAlert(true); c.setBackground(new Color(255, 204, 153)); c.setForeground(Color.BLACK); } else if (info.getAgeAlert() != 0 && (System.currentTimeMillis() - info.getAgeAlert() > info.getAgeAlert())) { info.setInAlert(true); c.setBackground(new Color(255, 204, 153)); c.setForeground(Color.BLACK); } else if (originalY % 2 == 0 && !isCellSelected(originalY, x)) { info.setInAlert(false); c.setBackground(Color.LIGHT_GRAY); c.setForeground(Color.BLACK); } else if (!isCellSelected(originalY, x)) { // // If not shaded, match the table's background info.setInAlert(false); c.setBackground(Color.WHITE); c.setForeground(Color.BLACK); } } return rval; }
From source file:net.schweerelos.parrot.ui.GraphViewComponent.java
@SuppressWarnings("serial") private void setupRenderContext(final VisualizationViewer<NodeWrapper, NodeWrapper> vis) { vis.setRenderer(new ParrotGraphRenderer()); vis.setPickSupport(new ParrotPickSupport(vis)); RenderContext<NodeWrapper, NodeWrapper> renderContext = vis.getRenderContext(); final PickedInfo<NodeWrapper> vertexPickInfo = vis.getPickedVertexState(); final PickedState<NodeWrapper> edgePickInfo = vis.getPickedEdgeState(); // hide all edge arrows except for those on outgoing edges of picked // nodes// www .ja v a2s . co m renderContext.setEdgeArrowPredicate(new Predicate<Context<Graph<NodeWrapper, NodeWrapper>, NodeWrapper>>() { @Override public boolean evaluate(Context<Graph<NodeWrapper, NodeWrapper>, NodeWrapper> context) { NodeWrapper edge = context.element; NodeWrapper source = graph.getSource(edge); return vertexPickInfo.isPicked(source); } }); // make edges straight lines to collapse parallel edges renderContext.setEdgeShapeTransformer(new EdgeShape.Line<NodeWrapper, NodeWrapper>()); // hide text of all edges except for outgoing edges of picked nodes renderContext.setEdgeLabelTransformer(new Transformer<NodeWrapper, String>() { @Override public String transform(NodeWrapper edge) { NodeWrapper source = graph.getSource(edge); NodeWrapper destination = graph.getDest(edge); if (vertexPickInfo.isPicked(source) && !vertexPickInfo.isPicked(destination)) { return edge.toString(); } else { return ""; } } }); renderContext.setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(COLOR_EDGE_LABEL) { @Override public <E> Component getEdgeLabelRendererComponent(JComponent vv, Object value, Font font, boolean isSelected, E edge) { Component component = super.getEdgeLabelRendererComponent(vv, value, font, isSelected, edge); component.setForeground(COLOR_EDGE_LABEL); return component; } }); // start from VertexLabelAsShapeDemo // this class will provide both label drawing and vertex shapes VertexLabelAsShapeRenderer<NodeWrapper, NodeWrapper> vlasr = new VertexLabelAsShapeRenderer<NodeWrapper, NodeWrapper>( renderContext); renderContext.setVertexShapeTransformer(vlasr); vis.setForeground(COLOR_NODE_TEXT); // customize the render context renderContext.setVertexLabelTransformer(new ToStringLabeller<NodeWrapper>()); renderContext.setVertexLabelRenderer(new DefaultVertexLabelRenderer(COLOR_NODE_PICKED_TEXT) { @Override public <V> Component getVertexLabelRendererComponent(JComponent vv, Object value, Font font, boolean isSelected, V vertexToRender) { Component component = super.getVertexLabelRendererComponent(vv, value, font, isSelected, vertexToRender); if (component instanceof JLabel) { JLabel label = (JLabel) component; // add a little bit of padding around the text Border originalBorder = label.getBorder(); label.setBorder(BorderFactory.createCompoundBorder(originalBorder, BorderFactory.createEmptyBorder(3, 2, 4, 2))); } // now set the colour/font too if (vertexToRender instanceof NodeWrapper) { NodeWrapper vertex = (NodeWrapper) vertexToRender; if (vertexPickInfo.isPicked(vertex)) { component.setForeground(COLOR_NODE_PICKED_TEXT); } else if (vertex.isHighlighted()) { component.setForeground(COLOR_NODE_HIGHLIGHTED_TEXT); component.setFont(font.deriveFont(Font.BOLD)); } else if (GraphViewHelper.hasPickedNeighbour(vertex, vertexPickInfo, graph)) { component.setForeground(COLOR_NODE_WITH_PICKED_NEIGHBOUR_TEXT); } else if (GraphViewHelper.hasPickedAdjacentEdge(vertex, edgePickInfo, graph)) { component.setForeground(COLOR_NODE_ADJACENT_EDGE_PICKED_TEXT); } else if (GraphViewHelper.hasHighlightedNeighbour(vertex, graph)) { component.setForeground(COLOR_NODE_WITH_HIGHLIGHTED_NEIGHBOUR_TEXT); } else { component.setForeground(COLOR_NODE_TEXT); } } return component; } }); // end from VertexLabelAsShapeDemo vis.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vis.setVertexToolTipTransformer(new Transformer<NodeWrapper, String>() { @Override public String transform(NodeWrapper vertex) { return vertex.getToolTipText(model); } }); // inspired by PluggableRendererDemo Transformer<NodeWrapper, Paint> vertexOutline = new Transformer<NodeWrapper, Paint>() { @Override public Paint transform(NodeWrapper vertex) { if (vertexPickInfo.isPicked(vertex)) { return COLOR_NODE_PICKED_BORDER; } else if (vertex.isHighlighted()) { return COLOR_NODE_HIGHLIGHTED_BORDER; } else { if (GraphViewHelper.hasPickedAdjacentEdge(vertex, edgePickInfo, graph)) { return COLOR_NODE_ADJACENT_EDGE_PICKED_BORDER; } if (GraphViewHelper.hasPickedNeighbour(vertex, vertexPickInfo, graph)) { return COLOR_NODE_WITH_PICKED_NEIGHBOUR_BORDER; } else if (GraphViewHelper.hasHighlightedNeighbour(vertex, graph)) { return COLOR_NODE_WITH_HIGHLIGHTED_NEIGHBOUR_BORDER; } // will get here only if no neighbour is picked/highlighted return COLOR_NODE_BORDER; } } }; renderContext.setVertexDrawPaintTransformer(vertexOutline); Transformer<NodeWrapper, Paint> vertexBackground = new Transformer<NodeWrapper, Paint>() { @Override public Paint transform(NodeWrapper vertex) { if (vertexPickInfo.isPicked(vertex)) { return COLOR_NODE_PICKED_BG; } else if (vertex.isHighlighted()) { return COLOR_NODE_HIGHLIGHTED_BG; } else { if (GraphViewHelper.hasPickedAdjacentEdge(vertex, edgePickInfo, graph)) { return COLOR_NODE_ADJACENT_EDGE_PICKED_BG; } if (GraphViewHelper.hasPickedNeighbour(vertex, vertexPickInfo, graph)) { return COLOR_NODE_WITH_PICKED_NEIGHBOUR_BG; } else if (GraphViewHelper.hasHighlightedNeighbour(vertex, graph)) { return COLOR_NODE_WITH_HIGHLIGHTED_NEIGHBOUR_BG; } return COLOR_NODE_BG; } } }; renderContext.setVertexFillPaintTransformer(vertexBackground); Transformer<NodeWrapper, Stroke> vertexStroke = new Transformer<NodeWrapper, Stroke>() { @Override public Stroke transform(NodeWrapper vertex) { if (vertexPickInfo.isPicked(vertex)) { return STROKE_VERTEX_PICKED; } else if (vertex.isHighlighted()) { return STROKE_VERTEX_HIGHLIGHTED; } Collection<NodeWrapper> edges = graph.getInEdges(vertex); for (NodeWrapper edge : edges) { if (edgePickInfo.isPicked(edge)) { return STROKE_VERTEX_INCOMING_EDGE_PICKED; } } edges = graph.getOutEdges(vertex); for (NodeWrapper edge : edges) { if (edgePickInfo.isPicked(edge)) { return STROKE_VERTEX_OUTGOING_EDGE_PICKED; } } // we'll only get here if none of the cases above applies return STROKE_VERTEX_DEFAULT; } }; renderContext.setVertexStrokeTransformer(vertexStroke); Transformer<NodeWrapper, Stroke> edgeStroke = new Transformer<NodeWrapper, Stroke>() { @Override public Stroke transform(NodeWrapper edge) { NodeWrapper edgeSource = graph.getSource(edge); if (edgePickInfo.isPicked(edge)) { return STROKE_EDGE_PICKED; } else if (vertexPickInfo.isPicked(edgeSource)) { return STROKE_EDGE_ADJACENT_NODE_PICKED; } else { return STROKE_EDGE_DEFAULT; } } }; renderContext.setEdgeStrokeTransformer(edgeStroke); Transformer<NodeWrapper, Paint> edgeColor = new Transformer<NodeWrapper, Paint>() { @Override public Paint transform(NodeWrapper edge) { if (edgePickInfo.isPicked(edge)) { return COLOR_EDGE_PICKED; } else if (GraphViewHelper.hasPickedAdjacentVertex(edge, vertexPickInfo, graph)) { return COLOR_EDGE_ADJACENT_VERTEX_PICKED; } else if (edge.isHighlighted()) { return COLOR_EDGE_HIGHLIGHTED; } else if (GraphViewHelper.hasHighlightedAdjacentVertex(edge, graph)) { return COLOR_EDGE_ADJACENT_VERTEX_HIGHLIGHTED; } else { return COLOR_EDGE; } } }; renderContext.setEdgeDrawPaintTransformer(edgeColor); // draw arrows in the same colour as edges renderContext.setArrowDrawPaintTransformer(edgeColor); renderContext.setArrowFillPaintTransformer(edgeColor); includePredicate = new IncludePredicate<Context<Graph<NodeWrapper, NodeWrapper>, NodeWrapper>>(); renderContext.setEdgeIncludePredicate(includePredicate); renderContext.setVertexIncludePredicate(includePredicate); vis.setBackground(COLOR_BACKGROUND); mouse = new DoubleClickPickingModalGraphMouse<NodeWrapper, NodeWrapper>(); mouse.add(new AbstractPopupGraphMousePlugin() { @Override protected void handlePopup(MouseEvent e) { if (!e.isPopupTrigger()) { return; } GraphElementAccessor<NodeWrapper, NodeWrapper> pickSupport = vis.getPickSupport(); if (pickSupport == null) { return; } NodeWrapper node = pickSupport.getVertex(layout, e.getX(), e.getY()); if (node == null) { node = pickSupport.getEdge(layout, e.getX(), e.getY()); } if (node == null) { return; } popup.setNodeWrapper(node); popup.show(vis, e.getX(), e.getY()); } }); mouse.setDoubleClickPickingPlugin(new DoubleClickPickingPlugin() { @Override void doubleClickOccurred(MouseEvent e) { GraphElementAccessor<NodeWrapper, NodeWrapper> pickSupport = vis.getPickSupport(); if (pickSupport == null) { return; } NodeWrapper node = pickSupport.getVertex(layout, e.getX(), e.getY()); if (node == null) { return; } fireNodeSelected(node); } }); vis.setGraphMouse(mouse); }