Example usage for javax.swing JList getFont

List of usage examples for javax.swing JList getFont

Introduction

In this page you can find the example usage for javax.swing JList getFont.

Prototype

@Transient
public Font getFont() 

Source Link

Document

Gets the font of this component.

Usage

From source file:Main.java

public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
        boolean hasFocus) {
    setEnabled(list.isEnabled());/*from   w w  w.ja v a  2s . c  om*/
    setSelected(((CheckListItem) value).isSelected());
    setFont(list.getFont());
    setBackground(list.getBackground());
    setForeground(list.getForeground());
    setText(value.toString());
    return this;
}

From source file:Main.java

public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
        boolean cellHasFocus) {
    setText(value.toString());/*from w ww.  jav a 2  s.c o  m*/

    setBackground(isSelected ? list.getSelectionBackground() : list.getBackground());
    setForeground(isSelected ? list.getSelectionForeground() : list.getForeground());

    setFont(list.getFont());
    setBorder((cellHasFocus) ? UIManager.getBorder("List.focusCellHighlightBorder") : m_noFocusBorder);

    return this;
}

From source file:de.unidue.inf.is.ezdl.gframedl.components.checkboxlist.CheckBoxListCellRenderer.java

@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
        boolean hasFocus) {

    choice.setEnabled(list.isEnabled());
    choice.setSelected(((CheckBoxListItem) value).isSelected());

    choice.setFont(list.getFont());
    choice.setText("<html>" + highlight(value.toString(), false) + "</html>");

    description.setFont(list.getFont());
    String text = ((CheckBoxListItem) value).getDescription();

    ImageIcon icon = ((CheckBoxListItem) value).getIcon();
    this.iconLabel.setIcon(icon);

    description.setText(text);/*from www. j av a2  s. c  o  m*/
    shortenDescription();

    int type = index % 2;
    if (isSelected && type == 0) {
        type = EVEN_SELECTED;
    }

    if (isSelected && type == 1) {
        type = ODD_SELECTED;
    }

    switch (type) {
    case ODD_SELECTED: {
        paintCell(Color.WHITE, SELECTION);
        break;
    }
    case EVEN_SELECTED: {
        paintCell(Color.WHITE, SELECTION);
        break;
    }
    case ODD: {
        paintCell(Color.BLACK, HIGHLIGHT);
        break;
    }
    case EVEN: {
        paintCell(Color.BLACK, Color.WHITE);
        break;
    }
    }

    return panel;
}

From source file:MainClass.java

public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
        boolean cellHasFocus) {
    Font theFont = null;//  w  w  w .java2  s.c  o m
    Color theForeground = null;
    String theText = null;

    JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected,
            cellHasFocus);

    if (value instanceof Object[]) {
        Object values[] = (Object[]) value;
        theFont = (Font) values[0];
        theForeground = (Color) values[1];
        theText = (String) values[2];
    } else {
        theFont = list.getFont();
        theForeground = list.getForeground();
        theText = "";
    }
    if (!isSelected) {
        renderer.setForeground(theForeground);
    }
    renderer.setText(theText);
    renderer.setFont(theFont);
    return renderer;
}

From source file:ComplexCellRenderer.java

public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
        boolean cellHasFocus) {
    Font theFont = null;/*from w  w  w  .j a v a  2 s.  co m*/
    Color theForeground = null;
    Icon theIcon = null;
    String theText = null;

    JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected,
            cellHasFocus);

    if (value instanceof Object[]) {
        Object values[] = (Object[]) value;
        theFont = (Font) values[0];
        theForeground = (Color) values[1];
        theIcon = (Icon) values[2];
        theText = (String) values[3];
    } else {
        theFont = list.getFont();
        theForeground = list.getForeground();
        theText = "";
    }
    if (!isSelected) {
        renderer.setForeground(theForeground);
    }
    if (theIcon != null) {
        renderer.setIcon(theIcon);
    }
    renderer.setText(theText);
    renderer.setFont(theFont);
    return renderer;
}

From source file:org.domainmath.gui.MainFrame.java

public CompletionProvider createCompletionProvider() {

    DefaultCompletionProvider provider = new DefaultCompletionProvider();

    JList l = new JList();

    AutoCompleteListCellRenderer cellRender = new AutoCompleteListCellRenderer(l.getFont(), l.getBackground(),
            l.getForeground(), l.getSelectionBackground(), l.getSelectionForeground());
    provider.setListCellRenderer(cellRender);

    OctaveM _m = new OctaveM();
    List a = _m.getKey("DomainMath_OctaveAutoComplete.ini");

    for (int i = 0; i < a.size(); i++) {
        provider.addCompletion(new BasicCompletion(provider, a.get(i).toString()));
    }/* ww  w  .  j  a v  a 2  s.c  o m*/

    return provider;

}

From source file:org.mbari.aved.ui.classifier.ClassModelListRenderer.java

public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
        boolean cellHasFocus) {
    if (isSelected) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());
    } else {//from  w ww  . ja  va  2s.c om
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }

    // Set the icon and text.  If icon was null, say so.
    if ((value != null) && value.getClass().equals(ClassModel.class)) {
        ClassModel model = (ClassModel) value;
        URL imageUrl = null;

        if (model != null) {
            ArrayList<String> listing = model.getRawImageFileListing();

            if (listing.size() > 0) {
                try {
                    imageUrl = new URL(
                            "file://" + model.getRawImageDirectory().toString() + "/" + listing.get(0));
                    icon = createImageIcon(imageUrl);
                } catch (MalformedURLException ex) {
                    Logger.getLogger(ClassModelListRenderer.class.getName()).log(Level.SEVERE,
                            "Error creating image icon for " + imageUrl.getFile(), ex);
                }

            } else {

                // Insert a default icon here
                URL url = Application.class.getResource("/org/mbari/aved/ui/images/missingframeexception.jpg");

                icon = new ImageIcon(url);
            }

            // scale icons to a normalized size here
            if (icon != null) {
                Image image = icon.getImage().getScaledInstance(50, 50, Image.SCALE_SMOOTH);

                icon = convertImageIcon(image, model.getColorSpace());
            }

            String name = model.getName();

            setIcon(icon);

            if (icon != null) {
                setText(name);
                setFont(list.getFont());
            } else {
                setDefaultText(name + " (no image available)", list.getFont());
            }
        }
    }

    return this;
}

From source file:org.netbeans.jcode.mvc.controller.MVCPanel.java

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor./*  ww w  .j  a v a 2  s  .com*/
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    packagePanel = new javax.swing.JPanel();
    packageLabel = new javax.swing.JLabel();
    packageCombo = new javax.swing.JComboBox();
    warningPanel = new javax.swing.JPanel();
    warningLabel = new javax.swing.JLabel();
    suffixPanel = new javax.swing.JPanel();
    namePane = new javax.swing.JLayeredPane();
    prefixField = new javax.swing.JTextField();
    entityLabel = new javax.swing.JLabel();
    suffixField = new javax.swing.JTextField();
    nameLabel = new javax.swing.JLabel();
    viewPanel = new javax.swing.JPanel();
    viewLabel = new javax.swing.JLabel();
    viewCombo = new javax.swing.JComboBox();
    eventObserversPanel = new javax.swing.JPanel();
    jCheckBox4 = new javax.swing.JCheckBox();
    jCheckBox1 = new javax.swing.JCheckBox();
    securityPanel = new javax.swing.JPanel();
    securityLabel = new javax.swing.JLabel();
    securityCompPanel = new javax.swing.JLayeredPane();
    authenticationCheckbox = new javax.swing.JCheckBox();
    csrfCheckbox = new javax.swing.JCheckBox();
    xssCheckbox = new javax.swing.JCheckBox();
    miscPanel = new javax.swing.JPanel();
    applicationConfigButton = new javax.swing.JButton();
    wrapper = new javax.swing.JLayeredPane();
    beanValidation = new javax.swing.JCheckBox();
    hybridClassCheckbox = new javax.swing.JCheckBox();

    packagePanel.setLayout(new java.awt.BorderLayout(10, 0));

    packageLabel.setLabelFor(packageCombo);
    org.openide.awt.Mnemonics.setLocalizedText(packageLabel,
            org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.packageLabel.text")); // NOI18N
    packageLabel.setPreferredSize(new java.awt.Dimension(100, 17));
    packagePanel.add(packageLabel, java.awt.BorderLayout.LINE_START);

    packageCombo.setEditable(true);
    packageCombo.setEditable(true);
    packageCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { " " }));
    packageCombo.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            packageComboPropertyChange(evt);
        }
    });
    packagePanel.add(packageCombo, java.awt.BorderLayout.CENTER);

    warningPanel.setLayout(new java.awt.BorderLayout(10, 0));

    warningLabel.setForeground(new java.awt.Color(200, 0, 0));
    warningLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    org.openide.awt.Mnemonics.setLocalizedText(warningLabel,
            org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.warningLabel.text")); // NOI18N
    warningPanel.add(warningLabel, java.awt.BorderLayout.CENTER);

    suffixPanel.setLayout(new java.awt.BorderLayout(10, 0));

    namePane.setLayout(new javax.swing.BoxLayout(namePane, javax.swing.BoxLayout.LINE_AXIS));

    prefixField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
    prefixField.setText(org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.prefixField.text")); // NOI18N
    prefixField.setToolTipText(
            org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.prefixField.toolTipText")); // NOI18N
    prefixField.setPreferredSize(new java.awt.Dimension(100, 27));
    prefixField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            prefixFieldPropertyChange(evt);
        }
    });
    namePane.add(prefixField);

    entityLabel.setForeground(javax.swing.UIManager.getDefaults().getColor("Button.shadow"));
    entityLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    org.openide.awt.Mnemonics.setLocalizedText(entityLabel,
            org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.entityLabel.text")); // NOI18N
    entityLabel.setPreferredSize(new java.awt.Dimension(58, 27));
    entityLabel.setRequestFocusEnabled(false);
    namePane.add(entityLabel);

    suffixField.setText(org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.suffixField.text")); // NOI18N
    suffixField.setPreferredSize(new java.awt.Dimension(100, 27));
    suffixField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            suffixFieldPropertyChange(evt);
        }
    });
    namePane.add(suffixField);

    suffixPanel.add(namePane, java.awt.BorderLayout.CENTER);

    org.openide.awt.Mnemonics.setLocalizedText(nameLabel,
            org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.nameLabel.text")); // NOI18N
    nameLabel.setPreferredSize(new java.awt.Dimension(100, 17));
    suffixPanel.add(nameLabel, java.awt.BorderLayout.WEST);

    viewPanel.setLayout(new java.awt.BorderLayout(10, 0));

    viewLabel.setLabelFor(viewCombo);
    org.openide.awt.Mnemonics.setLocalizedText(viewLabel,
            org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.viewLabel.text")); // NOI18N
    viewLabel.setPreferredSize(new java.awt.Dimension(100, 17));
    viewPanel.add(viewLabel, java.awt.BorderLayout.LINE_START);

    viewCombo.setModel(new DefaultComboBoxModel(ControllerReturnType.values()));
    viewCombo.setRenderer(new BasicComboBoxRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            if (isSelected) {
                setBackground(list.getSelectionBackground());
                setForeground(list.getSelectionForeground());
                if (index > -1) {
                    ControllerReturnType returnType = (ControllerReturnType) value;
                    list.setToolTipText(returnType.getDescription());
                }
            } else {
                setBackground(list.getBackground());
                setForeground(list.getForeground());
            }
            setFont(list.getFont());
            setText((value == null) ? "" : value.toString());

            return this;
        }
    });
    viewCombo.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            viewComboPropertyChange(evt);
        }
    });
    viewPanel.add(viewCombo, java.awt.BorderLayout.CENTER);

    eventObserversPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
            org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.eventObserversPanel.border.title"),
            javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
            javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11),
            new java.awt.Color(100, 100, 100))); // NOI18N
    eventObserversPanel.setLayout(new java.awt.GridLayout(2, 3));

    org.openide.awt.Mnemonics.setLocalizedText(jCheckBox4,
            org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.jCheckBox4.text")); // NOI18N
    jCheckBox4.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jCheckBox4ActionPerformed(evt);
        }
    });
    eventObserversPanel.add(jCheckBox4);

    org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1,
            org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.jCheckBox1.text")); // NOI18N
    eventObserversPanel.add(jCheckBox1);

    securityPanel.setLayout(new java.awt.BorderLayout(10, 0));

    org.openide.awt.Mnemonics.setLocalizedText(securityLabel,
            org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.securityLabel.text")); // NOI18N
    securityLabel.setPreferredSize(new java.awt.Dimension(100, 17));
    securityPanel.add(securityLabel, java.awt.BorderLayout.LINE_START);

    securityCompPanel.setLayout(new java.awt.GridLayout(1, 0));

    org.openide.awt.Mnemonics.setLocalizedText(authenticationCheckbox,
            org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.authenticationCheckbox.text")); // NOI18N
    securityCompPanel.add(authenticationCheckbox);

    org.openide.awt.Mnemonics.setLocalizedText(csrfCheckbox,
            org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.csrfCheckbox.text")); // NOI18N
    securityCompPanel.add(csrfCheckbox);

    org.openide.awt.Mnemonics.setLocalizedText(xssCheckbox,
            org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.xssCheckbox.text")); // NOI18N
    securityCompPanel.add(xssCheckbox);

    securityPanel.add(securityCompPanel, java.awt.BorderLayout.CENTER);

    miscPanel.setLayout(new java.awt.BorderLayout());

    org.openide.awt.Mnemonics.setLocalizedText(applicationConfigButton,
            org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.applicationConfigButton.text")); // NOI18N
    applicationConfigButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            applicationConfigButtonActionPerformed(evt);
        }
    });
    miscPanel.add(applicationConfigButton, java.awt.BorderLayout.EAST);

    beanValidation.setSelected(true);
    org.openide.awt.Mnemonics.setLocalizedText(beanValidation,
            org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.beanValidation.text")); // NOI18N
    beanValidation.setToolTipText(
            org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.beanValidation.toolTipText")); // NOI18N

    hybridClassCheckbox.setSelected(true);
    org.openide.awt.Mnemonics.setLocalizedText(hybridClassCheckbox,
            org.openide.util.NbBundle.getMessage(MVCPanel.class, "MVCPanel.hybridClassCheckbox.text")); // NOI18N

    wrapper.setLayer(beanValidation, javax.swing.JLayeredPane.DEFAULT_LAYER);
    wrapper.setLayer(hybridClassCheckbox, javax.swing.JLayeredPane.DEFAULT_LAYER);

    javax.swing.GroupLayout wrapperLayout = new javax.swing.GroupLayout(wrapper);
    wrapper.setLayout(wrapperLayout);
    wrapperLayout
            .setHorizontalGroup(wrapperLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(wrapperLayout.createSequentialGroup().addGap(114, 114, 114)
                            .addComponent(hybridClassCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, 172,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(beanValidation, javax.swing.GroupLayout.PREFERRED_SIZE, 151,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap(151, Short.MAX_VALUE)));
    wrapperLayout.setVerticalGroup(wrapperLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                    wrapperLayout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE).addGroup(wrapperLayout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(beanValidation, javax.swing.GroupLayout.PREFERRED_SIZE, 20,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(hybridClassCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, 0,
                                    Short.MAX_VALUE))
                            .addGap(10, 10, 10)));

    miscPanel.add(wrapper, java.awt.BorderLayout.CENTER);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(eventObserversPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(packagePanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(suffixPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(viewPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(securityPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(miscPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 0,
                                    Short.MAX_VALUE))
                    .addContainerGap())
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                            layout.createSequentialGroup().addContainerGap().addComponent(warningPanel,
                                    javax.swing.GroupLayout.DEFAULT_SIZE, 707, Short.MAX_VALUE)
                                    .addContainerGap())));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addGap(9, 9, 9)
                    .addComponent(suffixPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 20,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(15, 15, 15)
                    .addComponent(packagePanel, javax.swing.GroupLayout.PREFERRED_SIZE, 20,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(15, 15, 15)
                    .addComponent(miscPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 20,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(15, 15, 15)
                    .addComponent(viewPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 20,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(15, 15, 15)
                    .addComponent(securityPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(eventObserversPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(51, Short.MAX_VALUE))
            .addGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                    layout.createSequentialGroup().addContainerGap(279, Short.MAX_VALUE)
                                            .addComponent(warningPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                    20, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addContainerGap())));
}