Java Dynamic Menu Additions

Source: Internet
Author: User

Do it yourself. How to add a dynamic menu with a database configuration

private void CreateMenu () {
Imenudao dao = new Menudaoimpl ();
String SQL1 = "SELECT * from the menu where menuId like ' __ '";
String SQL2 = "SELECT * from the menu where menuId like ' ____ '";
Remember, this is the entity menu that you wrote yourself, not the Java itself.
List<menu> List1 = Dao.findall (SQL1);//First Level menu
List<menu> List2 = Dao.findall (SQL2);//Level Two menu

for (Menu Menu1:list1) {
JMenu temenu = new JMenu ();
JMenuItem teitem = null;
for (Menu menu2:list2) {
if (Menu2.getmenuid (). StartsWith (Menu1.getmenuid ())) {
Teitem = new JMenuItem ();
Teitem.setactioncommand (Menu2.getmenuid ());
Teitem.settext (Menu2.getmenuname ());
Teitem.settooltiptext (Menu2.getmenumemo ());
Because the inner layer traverses one submenu at a time, it must be quickly added below the first level menu
Temenu.add (Teitem);
}
}
Temenu.setactioncommand (Menu1.getmenuid ());
Temenu.settext (Menu1.getmenuname ());
Temenu.settooltiptext (Menu1.getmenumemo ());

This.menuBar.add (Temenu);
}
}

Java Dynamic Menu Additions

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.