aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to approach to disable or enable JButtons regarding user access status? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to approach to disable or enable JButtons regarding user access status?" Watch "How to approach to disable or enable JButtons regarding user access status?" New topic
Author

How to approach to disable or enable JButtons regarding user access status?

Kristjan Toots
Ranch Hand

Joined: Jun 03, 2011
Posts: 59

Hello,
I'm trying to create a simple GUI with couple of buttons and 2 different users. I would like to use the same GUI for "user" and "admin" where some of those buttons are disabled for "user".
I have imagined that I would create a template GUI with all the buttons and on run-time it will decide whether to disable certain buttons or not to.

I am a bit stuck coming up with proper solution since I don't quite know how to approach.

* I have thought about using 2D arrays where I add the button to the 1st dimension and I would use the 2nd dimension for deciding whether to enable or disable the button. Afterwards I would add those buttons to the JPanel from the array.

* I have thought about creating 2 classes (user & admin) where user has int value as "accessLevel" and admin extends from it and re-writes it with different value. Then I would use that "accessLevel" value to determine whether to disable or not to.

I would really appreciate some pseudo code or some other pointers how should I approach the given problem.


Please correct my english.
Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 563
Or a single User class that has a field that can be set for multi-level access, even if it's just two levels, admin and regular. Then, when a user logs in, the GUI will be set to reflect that person's access. The right buttons will be turned on, the others turned off, etc.


Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Kristjan Toots
Ranch Hand

Joined: Jun 03, 2011
Posts: 59

Thank you Sir for taking the time to reply.
I am not familiar with those topics, is it too much to ask for some key terms or some pointers to the required reading material?

Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 563
I suggest you start by reading up on how to use JButtons here. Or, if this your first Java GUI project, you should start at this page. Oracle is pushing the use of Netbeans GUI Builder, but I recommend you ignore that part and learn to code Swing by hand. It's not as challenging as they suggest.

Come back and ask questions as you need more help.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

Greg Brannon wrote:Oracle is pushing the use of Netbeans GUI Builder, but I recommend you ignore that part and learn to code Swing by hand. It's not as challenging as they suggest.


It's a greater challenge to learn the quirks of the visual designer, and especially so when you don't know what the auto-generated code does.


luck, db
There are no new questions, but there may be new answers.
 
Don't get me started about those stupid light bulbs.
 
subject: How to approach to disable or enable JButtons regarding user access status?