Results 1 to 3 of 3
  1. #1
    NotTooOld is offline Hostage
    Join Date
    Apr 2013
    Location
    China
    Posts
    128
    Rep Power
    0

    Default I don't know why I can't setEnabled() this JcomboBox

    I want it to be disabled when the program starts. That's done easy, but I can't seem to find the combination that will work to setEnabled(true). I want to set it true when a Lesson Set is chosen.
    I don't know why I can't setEnabled() this JcomboBox-screeny.jpg

    Sorry. Very late here. I should also say that I can't find the combination that allows me to compile this. I'm trying to make the change in this bit of code: (all of which is in the build GUI method)
    Java Code:
    JMenuItem mntmLS1 = new JMenuItem("Lesson Set 1");
    		mntmLS1.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				LSCBox.setEnabled(true); 
    			}
    		});
    This is where the JComboBox is Instantiated:
    Java Code:
    String cmBox[] = Utility.MakeLS1ComboBox("LS1LessonList.txt");
    		@SuppressWarnings({ "rawtypes", "unchecked" }) 
    		final JComboBox LSCBox = new JComboBox(cmBox);
    		
    		LSCBox.setFont(new Font("Tahoma", Font.BOLD, 11));
    		LSCBox.setMaximumSize(new Dimension(120, 20));
    		LSCBox.setMinimumSize(new Dimension(120, 20));
    		LSCBox.setPreferredSize(new Dimension(120, 20));
    		LSCBox.setEditable(false);
    		LSCBox.setEnabled(false);
    		ItemListener comboListener = new ItemListener(){
    
    			@Override
    			public void itemStateChanged(ItemEvent evt) {
    				int state = evt.getStateChange();
    				if (state == 1){
    					int i = Utility.ComboCardNumber(evt.getItem().toString());
    			//		System.out.println(i);         <---- Use  later to change cards
    				}
    				
    			}
    			
    		};
    		LSCBox.addItemListener(comboListener);
    		menuBar.add(LSCBox);
    I get red lines and the message "invalid modifiers" if I try to make the JComboBox public or static...
    I've done similar things (setEnabled) before by declaring the component "final," but that's not working here. Any ideas?
    Last edited by NotTooOld; 04-23-2013 at 07:51 PM.

  2. #2
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    5

    Default Re: I don't know why I can't setEnabled() this JcomboBox

    Can you please show us your complete code.

    Regards.

  3. #3
    NotTooOld is offline Hostage
    Join Date
    Apr 2013
    Location
    China
    Posts
    128
    Rep Power
    0

    Default Re: I don't know why I can't setEnabled() this JcomboBox

    Quote Originally Posted by Ronin View Post
    Can you please show us your complete code.

    Regards.
    You really want to look at 1400 lines of code? My design is likely all wrong, but nearly everything, and certainly this problem, all take place in the method that puts together the GUI. (915 lines and growing) I'm using Eclipse/WindowBuilder, which by default dumps all visual components into one method. The "action" handlers are also nested in there. I try to move as much out as I can, as you can see from this example.
    Java Code:
    mnInfo.add(mntmLessonPlanning);
    		
    		JMenuItem mntmAbout = new JMenuItem("About AlphaBest");
    		mntmAbout.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				String mess = Utility.ReadAboutFile("About.txt");
    				JOptionPane.showMessageDialog(null, mess);
    			}
    		});
    		mntmAbout.setFont(new Font("Tahoma", Font.PLAIN, 15));
    		mntmAbout.setHorizontalAlignment(SwingConstants.CENTER);
    		mnInfo.add(mntmAbout);
    I've found a work-around, but I still am confused as to why I can (inside an ActionEvent handler) setEnabled(true/false) some components, but not the JComboBox. Maybe because it has a listener attached? idk ... Moving on to the next challenge. :p
    Last edited by NotTooOld; 04-25-2013 at 06:19 AM.

Similar Threads

  1. Help with setEnabled
    By garnachito in forum New To Java
    Replies: 1
    Last Post: 07-08-2012, 02:32 PM
  2. setting JButton setEnabled() outside of main class
    By danborgir in forum New To Java
    Replies: 11
    Last Post: 05-07-2011, 05:03 PM
  3. JButton setEnabled
    By kbro3 in forum New To Java
    Replies: 5
    Last Post: 03-23-2011, 01:53 AM
  4. Problem with button.setEnabled
    By Dycu in forum SWT / JFace
    Replies: 0
    Last Post: 07-19-2010, 01:49 PM
  5. Replies: 4
    Last Post: 02-27-2009, 12:46 AM

Posting Permissions

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