Swing list Box component

Source: Internet
Author: User

public class Jlisttest extends jframe{
Private static final long serialversionuid=1l;
Public Jlisttest ()
{
Container Cp=getcontentpane ();
Cp.setlayout (NULL);
Jlist<string> jl=new jlist<> (New Mylistmodel ());
JScrollPane js=new JScrollPane (JL);
Js.setbounds (10, 10, 100, 100);
Cp.add (JS);
Settitle ("Use a list box in this form");
SetSize (200, 150);
SetVisible (TRUE);
Setdefaultcloseoperation (Windowconstants.exit_on_close);





}

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

}
Class Mylistmodel extends abstractlistmodel<string>{
Private string[] contents={"List 1", "List 2", "List 3", "List 4", "List 5", "List 6"};



@Override
public int GetSize () {
TODO auto-generated Method Stub
return contents.length;
}

@Override
Public String getelementat (int x) {
if (x<contents.length) {
return contents[x++];
}
else {
return null;
}
}

}


Swing 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.