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 ?
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 ).