PopupCombo Sample : ComboBox « Swing JFC « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Swing JFC » ComboBoxScreenshots 
PopupCombo Sample
PopupCombo Sample

import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.plaf.ComboBoxUI;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicArrowButton;
import javax.swing.plaf.basic.BasicComboBoxUI;

public class PopupComboSample {
  public static void main(String args[]) {
    String labels[] "A""B""C""D","E""F""G""H","I""J" };
    JFrame frame = new JFrame("Popup JComboBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    JComboBox comboBox = new JComboBox(labels);
    comboBox.setMaximumRowCount(5);
    comboBox.setUI((ComboBoxUIMyComboBoxUI.createUI(comboBox));
    contentPane.add(comboBox, BorderLayout.NORTH);

    frame.setSize(300200);
    frame.setVisible(true);
    comboBox.showPopup();
  }

  static class MyComboBoxUI extends BasicComboBoxUI {
    public static ComponentUI createUI(JComponent c) {
      return new MyComboBoxUI();
    }

    protected JButton createArrowButton() {
      JButton button = new BasicArrowButton(BasicArrowButton.EAST);
      return button;
    }
  }
}

           
       
Related examples in the same category
1. Using drop-down listsUsing drop-down lists
2. A fancy example of JComboBox with a custom renderer and editorA fancy example of JComboBox with a custom renderer and editor
3. Editable ComboBoxEditable ComboBox
4. Create a simple combobox
5. Font Chooser ComboBoxFont Chooser ComboBox
6. Color combobox rendererColor combobox renderer
7. Select the combobox by choose the nearby labelSelect the combobox by choose the nearby label
8. ComoboBox loads and saves items automatically from a fileComoboBox loads and saves items automatically from a file
9. Sharing a Model between a JList and JComboBoxSharing a Model between a JList and JComboBox
10. ComboBox Demo 2ComboBox Demo 2
11. Custom ComboBox with ImageCustom ComboBox with Image
12. ComboBox DemoComboBox Demo
13. List: Shared Data SampleList: Shared Data Sample
14. Selecting Combo SampleSelecting Combo Sample
15. MultiKey ComboMultiKey Combo
16. Dual Sample: JList and ComboBoxDual Sample: JList and ComboBox
17. ComboBox SampleComboBox Sample
18. Color ComboBox: ComboBoxEditor DemoColor ComboBox: ComboBoxEditor Demo
19. ArrayListComboBoxModel DemoArrayListComboBoxModel Demo
ww___w___.ja__v__a___2__s.c___o_m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.