Drop-down list box component

Source: Internet
Author: User

Package Com.java.charpter13;

Import Java.awt.Container;
Import Java.awt.FlowLayout;
Import Java.util.concurrent.locks.AbstractOwnableSynchronizer;

Import Javax.swing.AbstractListModel;
Import Javax.swing.ComboBoxModel;
Import Javax.swing.JComboBox;
Import Javax.swing.JFrame;
Import Javax.swing.JLabel;
Import javax.swing.WindowConstants;

public class Jcomboxmodeltest extends jframe{
Private static final long serialvesionuid=1l;
Jcombobox<string> jc=new jcombobox<> (New MyComboBox ());

JLabel j1=new JLabel ("Please select Document");

Public Jcomboxmodeltest ()
SetSize (160, 180);
SetVisible (TRUE);
Settitle ("Set drop-down list in Window");

Setdefaultcloseoperation (Windowconstants.exit_on_close);
Container Cp=getcontentpane ();
Cp.setlayout (New FlowLayout ());

Cp.add (J1);
Cp.add (JC);

public static void Main (string[] args) {
New Jcomboxmodeltest ();

Class MyComboBox extends abstractlistmodel<string> implements Comboboxmodel<string>
String Selecteditem=null;
String[] test={"id", "Military Certificate", "Student card", "Work permit"};

public int GetSize () {
TODO auto-generated Method Stub
return test.length;

Public String getelementat (int index) {
TODO auto-generated Method Stub
return Test[index];

public void Setselecteditem (Object anitem) {
Selecteditem= (String) Anitem;


Public Object GetSelectedItem () {
TODO auto-generated Method Stub
return SelectedItem;

public int GetIndex () {
for (int i = 0; i < test.length; i++) {
if (Test[i].equals (GetSelectedItem ()))
return i;
return 0;


Drop-down list box component

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.