Javase Study notes: Chapter tenth swing frequently uses control classes (ii)

Source: Internet
Author: User

7. JComboBox drop-down list
/*
* Initialize drop-down list
*/
public void Addcomb () {
string[] area = {"Shanxi province", "Shandong province", "Hebei province", "Shaanxi province"};
JComboBox jb=new JComboBox (area);
Jb.setsize (70, 20);
Jb.setlocation (120, 200);
Jb.setopaque (FALSE);
C.add (JB);
String[] area1 = {"Taiyuan", "Changzhi", "Xinzhou", "Yuci"};
JComboBox jb1=new JComboBox (AREA1);
Jb1.setsize (70, 20);
Jb1.setlocation (200, 200);
Jb1.setopaque (FALSE);
C.add (JB1);
C.setlayout (NULL);
}

8. JList List
/*
* Initialize List
*/
public void Addlist () {
string[] data = {"One", "one", "three", "four"};

JList jl=new JList (data);

Jl.setsize (100, 500);
Jl.setlocation (100, 50);
C.add (JL);
C.setlayout (NULL);
}

9. JTextArea Text Field
/*
* Initialize text area
*/
public void Addarea () {
JTextArea ja=new JTextArea ();
Ja.setsize (100, 40);
JScrollPane jp=new JScrollPane (JA);
Jp.setsize (200, 60);
Jp.setlocation (100, 100);
C.add (JP);
C.setlayout (NULL);
}
10. JMenu Create menu bar
/*
* Create a menu bar
*/
public void Addbar () {
Create a menu bar
JMenuBar jmb=new JMenuBar ();
Jmb.setsize (This.getwidth (), 30);
Jmb.setlocation (0, 0);
C.add (JMB);
C.setlayout (NULL);
Create a Menu
JMenu filemenu=new JMenu ("File (F)");
JMenu editmenu=new JMenu ("edit (E)");
JMenu editmenu1=new JMenu ("Format (O)");
JMenu editmenu2=new JMenu ("View (V)");
JMenu editmenu3=new JMenu ("Help (H)");
Set shortcut keys
Filemenu.setmnemonic (' f ');
Editmenu.setmnemonic (' e ');
Editmenu1.setmnemonic (' O ');
Editmenu2.setmnemonic (' V ');
Editmenu3.setmnemonic (' h ');
Add menu to menu bar
Jmb.add (Filemenu);
Jmb.add (Editmenu);
Jmb.add (EDITMENU1);
Jmb.add (EDITMENU2);
Jmb.add (EDITMENU3);
Create a menu item
JMenuItem it1=new JMenuItem ("new");
JMenuItem it2=new JMenuItem ("Save");
JMenuItem it3=new JMenuItem ("open");
JMenuItem it4=new JMenuItem ("exit");
Add menu item to File menu
Filemenu.add (IT1);
Filemenu.add (IT2);
Filemenu.add (IT3);
Adding a cutting character
Filemenu.addseparator ();
Filemenu.add (IT4);
Create a menu item
JMenuItem it11=new jmenuitem ("copy");
JMenuItem it12=new JMenuItem ("cut");
JMenuItem it13=new JMenuItem ("paste");
JMenuItem it14=new JMenuItem ("find");
Adding menu items to the Edit menu
Editmenu.add (IT11);
Editmenu.add (it12);
Editmenu.add (IT13);
Editmenu.add (it14);



}

Javase Study notes: Chapter tenth swing frequently uses control classes (ii)

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.