making visible disabled JComponents


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: making visible disabled JComponents

  1. #1
    Join Date
    Jun 2004
    Posts
    29

    making visible disabled JComponents

    Hello everyone,

    I'm just wondering if there's a way to set a JComponent to disabled (ie. Component.setEnabled(false)) without having its appearance greyed out. That is - conserve it's look & feel such that the user would not be able to tell it was disabled unless she clicked on it.

    Gib

  2. #2
    Join Date
    Sep 2003
    Posts
    18
    You could simply leave it enabled but just have the program not do anything when the button was clicked. Wouldn't that work?

  3. #3
    Join Date
    Jun 2004
    Posts
    29

    yes but...

    I would, except that it's not a JButton. It's a JSpinner. What I have in mind is to prevent the user from entering anything but integers greater than 0. So I want to disallow for strings like "aaa" or "#$%" not only being processed but not even entered to begin with. I found I could disable the JTextField in the editor:

    Spinner.getEditor().getTextField().setEnabled(false);

    So that the TextField is disabled but at the same time leaves the Spinner buttons (up and down) still active so the user can still spin through {1,2,3,...}. Nevertheless, the whole JSpinner is greyed out which makes it look ugly.

    Is there any other way around this?

    Gib

  4. #4
    Join Date
    Feb 2004
    Posts
    808

    Re: making visible disabled JComponents

    Originally posted by gibby
    Hello everyone,

    I'm just wondering if there's a way to set a JComponent to disabled (ie. Component.setEnabled(false)) without having its appearance greyed out. That is - conserve it's look & feel such that the user would not be able to tell it was disabled unless she clicked on it.

    Gib
    no, because this is not good HCI practice. Why would you want a component that looks like it works, but doesnt actually work when the user tries?

    How would you like to be stuck in a burning building, with fire-doors around the place but every time you approach them and push them, you realise that they are just painted on the wall, they arent actually doors at all?

    Never lose sight of that fact that you wrote a program; it takes a modicum of intelligence and understanding of computers to do so. Users did not write your program, they do not know how it works, nor are they all the most intelligent people on the planet.
    When faced with something unknown, frightening and incomprehensible, they will initially look for things they might recognise - things that might get them from A to B.. If you go misleading them you will irritate them no end.

    Plus, if someone like me every used your program, you would get a very lengthy, and very critical email, offering advice on the weak points of your user interface.

    In your particular situation you must consider all inputs, you must consider the inputs that are valid, and constrain the user to only those inputs. If they type alphamerics, kill the event so that no alphameric appears in the field, only numeric.. etc
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center