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: Disable items in JComboBox or ?

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Disable items in JComboBox or ?

    So I have a project where I'm creating a camping reservation program and it allows for only 5 camp sites and once each camp site is selected I need to make that site unavailable (or show a JOptionPane saying it has already been occupied and make it unavailable) until the person checks out of the site . My idea was to use a JComboBox to show the site options and disable the sites that have already been checked in but I'm not sure if I can do that . Any suggestions ?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    184
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: Disable items in JComboBox or ?

    a) You can use a JMenuBar, which allows enabling/disabling the JMenuItems b) You could just remove the items that are not available from the JComboBox c) You could provide a custom renderer for the JComboBox items to grey them out ( How to Use Combo Boxes (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components) has a demo how you can add a custom renderer) - the items can still be selected and fire events, but from the users point of view (provided you don't react to the action) they wouldn't know the difference (see Enable/Disable JComboBox Items ).

Similar Threads

  1. Replies: 7
    Last Post: February 2nd, 2013, 11:07 AM
  2. Button disable
    By deependeroracle in forum AWT / Java Swing
    Replies: 6
    Last Post: April 22nd, 2012, 10:06 AM
  3. JComboBox help again but different help 75+ items in it
    By derekxec in forum AWT / Java Swing
    Replies: 7
    Last Post: August 27th, 2011, 07:53 PM
  4. disable a button ?
    By dime111 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 28th, 2011, 03:58 PM
  5. Insert master or gloabal java script to disable globally onclick
    By karnesb in forum Java Theory & Questions
    Replies: 2
    Last Post: October 12th, 2008, 05:10 PM