Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Error when trying to hide JComboBox Option.

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    4
    My Mood
    Confused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Error when trying to hide JComboBox Option.

    Cannot switch on a value of type Object. Only convertible int values, strings or enum variables are permitted


    I'm trying to hide and option using switch statement but this is the error i receive.
    could someone help me fix this please?

      public void actionPerformed(ActionEvent e)
            {
                if(e.getSource() == comboDest1)
                {
                    switch(comboDest1.getSelectedItem())
                    {
                        case "Crete":
                            //throw away the old accomodation array, and assign a new array to it with specific accomodations
                            Accomodation = new String[]{"Select your Accomodation","Hotel", "Villa", "Bed & Breakfast"};
                            //throw away the old combobox and make a new one with the new accomodation array
                            comboAccom1 = new JComboBox(Accomodation);
                            break;
     
                    }
                }
            }
            }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Error when trying to hide JComboBox Option.

    What don't you understand about the error message?

    Actually, this error presents an opportunity for you to get into the JComboBox API to understand the error message. While you're there, review the available JComboBox methods and consider another, more elegant approach to rebuilding the array for the new JComboBox.

Similar Threads

  1. Replies: 10
    Last Post: April 21st, 2013, 09:28 AM
  2. [SOLVED] Error for JCombobox Editable
    By remedys in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 30th, 2013, 11:09 PM
  3. how to hide jtable in jframe
    By vitiazaltair in forum AWT / Java Swing
    Replies: 2
    Last Post: February 7th, 2012, 11:12 AM
  4. Hide/Show Form?
    By chickenhawk in forum What's Wrong With My Code?
    Replies: 11
    Last Post: July 1st, 2011, 06:26 AM
  5. JComboBox null pointer Exception error
    By F_Arches in forum AWT / Java Swing
    Replies: 2
    Last Post: November 29th, 2009, 02:32 PM

Tags for this Thread