Package gnu.testlet.javax.swing.plaf.basic.BasicComboBoxUI

Examples of gnu.testlet.javax.swing.plaf.basic.BasicComboBoxUI.MyBasicComboBoxUI


    {
      e.printStackTrace();
    }
    JComboBox cb = new JComboBox();
    cb.setEditable(true);
    MyBasicComboBoxUI ui = new MyBasicComboBoxUI();
    cb.setUI(ui);
    JTextField tf = (JTextField) cb.getEditor().getEditorComponent();
    int columns = tf.getColumns();
    FontMetrics fm = cb.getFontMetrics(cb.getFont());
   
    // for an editable JComboBox the display size is calculated from the
    // preferred size of the JTextField it seems, or the prototype display
    // value in some cases...
    int width = fm.charWidth('m') * columns;
    int height = fm.getHeight() + 2// the 2 seems to be a fixed margin
   
    // not sure why the width here needs + 1..
    harness.check(ui.getDisplaySize(), new Dimension(width + 1, height));
   
    cb.addItem("ABC");
    harness.check(ui.getDisplaySize(), new Dimension(width, height));

    cb.addItem("A longer item");
    harness.check(ui.getDisplaySize(), new Dimension(width, height));

    cb.setPrototypeDisplayValue("Prototype");
    harness.check(ui.getDisplaySize(), new Dimension(width, height));

    cb.setPrototypeDisplayValue("Long Prototype Display Value");
    width = fm.stringWidth("Long Prototype Display Value") + 2;
    harness.check(ui.getDisplaySize(), new Dimension(width, height));
   
    // restore a sane look and feel
    try
    {
      UIManager.setLookAndFeel(new MetalLookAndFeel());
View Full Code Here

TOP

Related Classes of gnu.testlet.javax.swing.plaf.basic.BasicComboBoxUI.MyBasicComboBoxUI

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.