Java JComboBox getMaxWidth(final JComboBox combo, final FontMetrics fm)

Here you can find the source of getMaxWidth(final JComboBox combo, final FontMetrics fm)

Description

get Max Width

License

Open Source License

Declaration

public static int getMaxWidth(final JComboBox<String> combo, final FontMetrics fm) 

Method Source Code

//package com.java2s;

import java.awt.FontMetrics;

import javax.swing.JComboBox;

public class Main {
    public static int getMaxWidth(final JComboBox<String> combo, final FontMetrics fm) {
        int maxLen = 0;
        for (int i = 0; i < combo.getItemCount(); i++) {
            String str = combo.getItemAt(i);
            int wi = fm.stringWidth(str);
            if (wi > maxLen) {
                maxLen = wi;//  w ww.  j a v a2  s .  c  o m
            }
        }
        return maxLen + 20; // leave room for the scroll bar
    }
}

Related

  1. generateComboBoxFor(Object... objs)
  2. getAgeComboBox()
  3. getComboBoxDisabledBackground()
  4. getEOL(JComboBox eolCombo)
  5. getJComboBoxString(JComboBox comboBox)
  6. getOnlyComboBox(Container owner)
  7. getPrinterJComboBox()
  8. getScrollBarWidth(JComboBox comboBox, JScrollPane scrollPane)
  9. initCombo(JComboBox combo)