Example usage for java.awt Component setFont

List of usage examples for java.awt Component setFont

Introduction

In this page you can find the example usage for java.awt Component setFont.

Prototype

public void setFont(Font f) 

Source Link

Document

Sets the font of this component.

Usage

From source file:Main.java

/**
 * Change a component's Font size.//from  w  w w.  j  av a 2s  .co m
 * <p>
 * The Font family and Font style are preserved in the updated Font.
 * @param component The component to change the Font presentation of.
 * @param size The new size of Font.
 * @return The new Font installed to the component.
 */
public static Font changeFontSize(Component component, float size) {
    Font existingFont = component.getFont();
    Font newFont = existingFont.deriveFont(size);
    component.setFont(newFont);
    return newFont;
}

From source file:Main.java

public static void removeFontAttr(Component component, Object key) {
    Font original = component.getFont();
    Map attributes = original.getAttributes();
    attributes.remove(key);//from   w ww.  j  a v a 2  s.c  om
    component.setFont(original.deriveFont(attributes));
}

From source file:Main.java

public static void setFontAttribute(Component component, Object key, Object value) {
    Font original = component.getFont();
    Map attributes = original.getAttributes();
    attributes.put(key, value);/*from   w  w  w  . j  av a 2  s .  com*/
    component.setFont(original.deriveFont(attributes));
}

From source file:de.codesourcery.eve.skills.ui.components.AbstractComponent.java

protected static void setMonospacedFont(Component comp) {

    final int size;
    if (comp.getFont() != null) {
        size = comp.getFont().getSize();
    } else {/*from w w w  .  ja v a  2  s.c om*/
        size = 12;
    }
    Font font = new Font("Monospaced", Font.PLAIN, size);

    comp.setFont(font);
}

From source file:com.db4o.sync4o.ui.Db4oSyncSourceConfigPanel.java

private void setupControls() {

    // Layout and setup UI components...

    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    add(_namePanel);/*from w ww  .ja v a2 s  .co m*/
    _namePanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    add(_fieldsPanel);
    _fieldsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    add(_classConfigsTree);
    _classConfigsTree.setAlignmentX(Component.LEFT_ALIGNMENT);
    _classConfigsTree.setPreferredSize(new Dimension(300, 300));
    add(_buttonsPanel);
    _buttonsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

    JLabel l;

    // Admin UI Management Panels use a title
    // (in a particular "title font") to identify themselves
    l = new JLabel("Edit Db4oSyncSource Configuration", SwingConstants.CENTER);
    l.setBorder(new TitledBorder(""));
    l.setFont(titlePanelFont);
    _namePanel.add(l);

    GridBagConstraints labelConstraints = new GridBagConstraints();
    labelConstraints.gridwidth = 1;
    labelConstraints.fill = GridBagConstraints.NONE;
    labelConstraints.weightx = 0.0;
    labelConstraints.gridx = 0;
    labelConstraints.gridy = 0;
    labelConstraints.anchor = GridBagConstraints.EAST;

    GridBagConstraints fieldConstraints = new GridBagConstraints();
    fieldConstraints.gridwidth = 2;
    fieldConstraints.fill = GridBagConstraints.HORIZONTAL;
    fieldConstraints.weightx = 1.0;
    fieldConstraints.gridx = 1;
    fieldConstraints.gridy = 0;

    _fieldsPanel.add(new JLabel("Source URI: "), labelConstraints);
    _fieldsPanel.add(_sourceUriValue, fieldConstraints);

    labelConstraints.gridy = GridBagConstraints.RELATIVE;
    fieldConstraints.gridy = GridBagConstraints.RELATIVE;

    _fieldsPanel.add(new JLabel("Name: "), labelConstraints);
    _fieldsPanel.add(_nameValue, fieldConstraints);

    fieldConstraints.gridwidth = 1;

    _fieldsPanel.add(new JLabel("db4o File: "), labelConstraints);
    _fieldsPanel.add(_dbFileValue, fieldConstraints);

    _dbFileValue.setEditable(false);

    fieldConstraints.gridwidth = 2;

    GridBagConstraints buttonConstraints = new GridBagConstraints();
    buttonConstraints.gridwidth = 1;
    buttonConstraints.fill = GridBagConstraints.NONE;
    buttonConstraints.gridx = 2;
    buttonConstraints.gridy = 3;
    _dbFileLocateButton.setText("...");
    _fieldsPanel.add(_dbFileLocateButton, buttonConstraints);

    buttonConstraints.gridwidth = 3;
    buttonConstraints.fill = GridBagConstraints.NONE;
    buttonConstraints.gridx = 0;
    buttonConstraints.gridy = GridBagConstraints.RELATIVE;
    buttonConstraints.anchor = GridBagConstraints.CENTER;

    // Ensure all the controls use the Admin UI standard font
    Component[] components = _fieldsPanel.getComponents();
    for (int i = 0; i < components.length; i++) {

        Component c = components[i];
        c.setFont(defaultFont);

    }

    _confirmButton.setText("Add");
    _buttonsPanel.add(_confirmButton);

}

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);//w ww . j a  v  a2s  .c om

        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:com.raddle.tools.MergeMain.java

private void setCellRenderer(JList list) {
    list.setCellRenderer(new DefaultListCellRenderer() {

        private static final long serialVersionUID = 1L;

        @Override/*from  ww w . j a v  a  2s . com*/
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value != null) {
                PropertyLine line = (PropertyLine) value;
                boolean isInSelected = false;
                for (int selectedIndex : list.getSelectedIndices()) {
                    if (index == selectedIndex) {
                        isInSelected = true;
                    }
                }
                if (!isInSelected) {
                    if (CompareResult.extra == line.getCompareResult()) {
                        c.setBackground(new Color(0xFFC48E));
                    } else if (CompareResult.different == line.getCompareResult()) {
                        c.setBackground(new Color(0xBBBBFF));
                    }
                }
                if (line.getState() != null) {
                    if (LineState.added == line.getState()) {
                        c.setForeground(new Color(0xCC0033));
                    } else if (LineState.updated == line.getState()) {
                        c.setForeground(new Color(0x0066CC));
                    } else if (LineState.deleted == line.getState()) {
                        if (line.getOriginalValue() == null) {
                            c.setForeground(new Color(0xAAAAAA));
                        } else {
                            c.setForeground(new Color(0x666666));
                        }
                        Map<Attribute, Object> map = new HashMap<Attribute, Object>();
                        map.put(TextAttribute.FONT, c.getFont());
                        map.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
                        c.setFont(Font.getFont(map));
                    }
                }
            }
            return c;
        }

    });
}

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/*from  w  ww . j  av a 2 s . c o 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);

}

From source file:nl.ctmm.trait.proteomics.qcviewer.utils.Utilities.java

/**
 * Set the specified font for the component and if it is a container then do it for all its child components too.
 *
 * @param component the component for which the font will be set (and for its children if there are any).
 * @param font the font to set./*from  w  w  w. j  a  v a 2  s  . co m*/
 */
public static void setFontContainer(final Component component, final Font font) {
    component.setFont(font);
    if (component instanceof Container) {
        for (final Component child : ((Container) component).getComponents()) {
            setFontContainer(child, font);
        }
    }
}

From source file:org.drugis.addis.gui.renderer.CategoryComboboxRenderer.java

public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
        boolean cellHasFocus) {

    // Pre-processing 
    boolean postprocess = false;
    if (value instanceof ChoiceNode) {
        postprocess = true;/* w w  w . j  a  v  a2  s .c o  m*/
        String property = StringUtils.lowerCase(value.toString());
        if (d_alternate) {
            value = "Consider " + property;
        } else {
            value = "Consider " + property + " first";
        }
    }

    Component c = d_defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    //Post-processing 
    if (postprocess || value instanceof CategorySpecifiers
            || (value instanceof LeafNode && value.toString().equals(LeafNode.NAME_EXCLUDE))) {
        c.setFont(c.getFont().deriveFont(Font.BOLD));
    }
    return c;
}