Results 1 to 2 of 2
  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,037
    Rep Power
    8

    Default JCheckBoxMenuItem read out

    Imagen I have a long list of JCheckBoxMenuItem at a JMenu
    The user makes multiples selections.
    And I would like to read these selections at a specific moment,
    how would I do that?

  2. #2
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,037
    Rep Power
    8

    Default Re: JCheckBoxMenuItem read out

    sure I could do this:

    Java Code:
     checkb = new JCheckBoxMenuItem[fnts.length];
                for (int i = 0; i < fnts.length; i++) {
                    font = new Font(fnts[i], Font.PLAIN, 16);
                    checkb[i] = new JCheckBoxMenuItem(fnts[i]);
                    //fontcb.setActionCommand(fnts[i]);
                    checkb[i].setFont(font);
                    checkb[i].addActionListener(menulistener);
                    fontlist.add(checkb[i]);
                }
    and check like this:

    Java Code:
    AbstractAction selectedFontsAction = new AbstractAction() {
                {	// Constructor
                    putValue(NAME, "Selected Fonts");
                    putValue(SMALL_ICON, IconImport.getImageIcon("whatever"));
                    putValue(MNEMONIC_KEY, new Integer('N'));
                    putValue(SHORT_DESCRIPTION, "Creates whatever");
                    putValue(LONG_DESCRIPTION, "Creating whatever...");
                }
                public void actionPerformed(ActionEvent evt) {
                        fontgroup.clearSelection(); // clear previous selection
                        fontshorlist [10] = new String();
                        if (true) {
                            for (int i = 0; i < fonts.length; i++) {
                                if  (checkb[i].isSelected()) {
                                    System.out.println(fonts[i]);
                                    
                                }
                            }
                        }      
                }
            };
    bur isn't there an easy way?

Similar Threads

  1. position text/ icon at JCheckBoxMenuItem
    By willemjav in forum AWT / Swing
    Replies: 5
    Last Post: 03-30-2013, 11:03 AM
  2. Replies: 0
    Last Post: 11-15-2011, 09:13 PM
  3. why one row is not read?
    By j2me64 in forum JDBC
    Replies: 1
    Last Post: 03-09-2011, 09:39 AM
  4. JCheckBoxMenuItem as JRadioButtonMenuItem
    By nik_meback in forum AWT / Swing
    Replies: 4
    Last Post: 12-16-2010, 12:19 PM
  5. Replies: 5
    Last Post: 10-17-2008, 02:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •