About JComboBox in NetBeans (check box)

Source: Internet
Author: User
Tags netbeans

1. Put options in the reciprocating box (added according to the database)

(1) First, the default Item1234 in attribute->model is emptied

(2) Get the data in the database and put it in.

Selectcourseview scv=NewSelectcourseview (); intSelectindex=-1; Syscoursedao SCD=NewSyscoursedaoimpl (); List<CourseView> courselist =Scd.queryallcourse ();
Get a table that holds the view, and then put in
Add excuses to your DAO package to get all the course names PublicTeascoreframe () {initcomponents ();      INITDEP (); This method must be placed after initcomponents (), initialize the component first, and then put the content. } Public voidInitdep () { for(Courseview cs:courselist) { This. Comcourseid.additem (Cs.getid ()); Iterate through the entire table and put it in one place}}

2. Get the current contents of the check box

Private voidBtnsearchactionperformed (java.awt.event.ActionEvent evt) {
First, empty the contents of the table and put the DefaultTableModel DTM= (DefaultTableModel) This. Tblteasearchselect.getmodel (); while(Dtm.getrowcount () >0) {Dtm.removerow (0); } //1. Get DefaultTableModel//2. Remove content from current table//3. Display data in table by vector object intSs= Integer.parseint (( This. Comcourseid.getselecteditem ()). ToString ());
//Comcourseid.getselecteditem () obtains an int, but cannot be directly equal, converted to a string and converted to int
Teacherdao TS New
List<SelectCourseView> scvlist=

For
New





3. Select the item that you want to display according to the check box in the table

This is a relatively simple

1  for(inti=0;i< This. Cbdep.getmodel (). GetSize (); i++)   {2     //traverse each item in the drop-down box to find the item that matches the selected item3Department dept= (Department) This. Cbdep.getitemat (i);4         if(Depa.equals (Dept.getdepname ()))5         {6              This. Cbdep.setselectedindex (i);7            }8}

About JComboBox in NetBeans (check box)

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.