aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How to use FocusListener for ConfigOptions Panel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "How to use FocusListener for ConfigOptions Panel" Watch "How to use FocusListener for ConfigOptions Panel" New topic
Author

How to use FocusListener for ConfigOptions Panel

Savas Aydin
Greenhorn

Joined: Sep 09, 2011
Posts: 12
Hi All,

I want to implement a common configuration panel in my GUI like described in Andrew's book. I will disable action buttons if configuration is not valid. But I have a problem related to focus listener. Action buttons aren't enabled in some cases. For instance, in standalone mode, connect button is left disabled after user enters a valid database path from keyboard because focus lost event isn't thrown (user didn't clicked outside of database location text field). There is no problem when user clicks Browse button and selects file with file chooser. Do you think this is acceptable?

Thanks in advance for your help.
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

Savas Aydin wrote:I want to implement a common configuration panel in my GUI like described in Andrew's book.


I must admit I'm not a fan of this. It makes the code far more complicated than it needs to be for very little (if any) gain.

Savas Aydin wrote:I will disable action buttons if configuration is not valid. But I have a problem related to focus listener. Action buttons aren't enabled in some cases. For instance, in standalone mode, connect button is left disabled after user enters a valid database path from keyboard because focus lost event isn't thrown (user didn't clicked outside of database location text field). There is no problem when user clicks Browse button and selects file with file chooser. Do you think this is acceptable?


Why not just leave the connect button enabled all the time (apart from when it is clicked on)? You can validate the file when the user clicks on the connect button.




SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2267
    
    3

Savas Aydin wrote:Do you think this is acceptable?


Hum... at most, I'd say there is a problem with usability. But... I wouldn't add such complexity. I simply provided a text field where the user provides the database file path, and when the OK button is pressed, then I verify if the user provided a valid path.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

I also have a common panel for the configuration settings, combined with disabling buttons using a FocusListener.

So I re-ran my application and I'm experiencing the same behavior: when user enters the path to the database file location manually the Connect button is not disabled. When the user clicks the button, an error message is shown and the button is disabled.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

Roel De Nijs wrote:When the user clicks the button, an error message is shown and the button is disabled.


Why is an error message shown?
Savas Aydin
Greenhorn

Joined: Sep 09, 2011
Posts: 12
Roel De Nijs wrote:I also have a common panel for the configuration settings, combined with disabling buttons using a FocusListener.

So I re-ran my application and I'm experiencing the same behavior: when user enters the path to the database file location manually the Connect button is not disabled. When the user clicks the button, an error message is shown and the button is disabled.


Hi Roel, How did you solve the following issue (for standalone client)?

1) After user enters an invalid file, the application shows a error dialog and disable connect button (I am assuming you don't enable it unless valid config entered).
2) User enters a valid database path using keyboard (without using file chooser)
3) I guess connect button will not be enabled unless user press TAB (or any action that will cause focus loss)

I dediced not to use MCV and Observer for the assighment because application is very simple to apply these patters. Observer would decrease the coupling between components but I think ConfigOptions isn't complex enough to see advantage of Observer pattern. I just used the common config panel and i handled form validation like Roberto described in OCMJD Paper.

Thanks for your help,
Savas
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

I'm no GUI expert, but disabling and enabling GUI components based on behaviour like this is not helpful to the end user. The end user has no idea why a certain component is disabled - they have to guess.

There is no benefit to disabling the connect button. Simply validate the file specified when the user clicks on the connect button.

If you use Windows OS. Open up Notepad. Choose File->Open from the menu. Look at the Open button that is displayed on the File Chooser dialog - is the Open button disabled? Type in an invalid file name - is the Open button disabled?
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

Sean Keane wrote:Why is an error message shown?

To inform the user the selection he made is not a valid one and he should make another selection (existing file, readible, writable, not empty,...)
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

Savas Aydin wrote:1) After user enters an invalid file, the application shows a error dialog and disable connect button (I am assuming you don't enable it unless valid config entered).
2) User enters a valid database path using keyboard (without using file chooser)
3) I guess connect button will not be enabled unless user press TAB (or any action that will cause focus loss)

Exactly
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

Sean Keane wrote:The end user has no idea why a certain component is disabled - they have to guess.

Not true, user gets an error message indicating what's wrong and what's expected to continue. And it's also mentioned in the user manual.

Sean Keane wrote:There is no benefit to disabling the connect button.

It simply fits the look-and-feel of my GUI: it's restrictive where possible (no chars in numeric fields, buttons disabled when it has no use clicking them,...)

Sean Keane wrote:If you use Windows OS. Open up Notepad. Choose File->Open from the menu. Look at the Open button that is displayed on the File Chooser dialog - is the Open button disabled? Type in an invalid file name - is the Open button disabled?

No, it's still enabled. But that's their design, I made my own (and used it consistently throughout my whole application).
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

Roel De Nijs wrote:And it's also mentioned in the user manual.


Users don't read manuals - they have expected behaviour based on previous applications they have used.

Because many applications follow a similar design, end users have a general expectation of certain behaviour. They expect the menus to be at the top of the application etc.

The vast majority of applications I have used would never enable\disable a button by silently validating a file entered. Based on this, it would be unexpected behaviour when this occurs.

The only applications I have come across that change the state of buttons like this are applications aimed at technical users - which wouldn't be the target audience of this project. Eclipse for example disables the "Finish" button when you are creating a class. It only enables the button when a valid class name is entered.

I understand you have documented your approach and you convey some information to the user about why the button is disabled. But it is generally unexpected behaviour and there is nothing to be gained from it. You can simply validate the file when you user clicks on the button - then no need for setting\unsetting the button, no need to document it in your instructions, no need to convey additional information in your user interface to explain why the button is disabled.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

Sean Keane wrote:The only applications I have come across that change the state of buttons like this are applications aimed at technical users - which wouldn't be the target audience of this project. Eclipse for example disables the "Finish" button when you are creating a class. It only enables the button when a valid class name is entered.

Funny that you mention this. Because Eclipse is more and more used as a framework/technology to develop client applications for non-technical users. Exactly what I'm doing these days. And because you are using Eclipse you'll have the same look-and-feel as for the technical users. The Finish-button is indeed disabled when the wizard has enough information to fulfill the request. And in my opinion it makes sense: there is no use at all to proceed with an incomplete request (because you'll certainly get some kind of validation error), so you disable the button.

Sean Keane wrote:You can simply validate the file when you user clicks on the button

I'll guess when the provided file is not valid you'll also displays some message to inform the user (and that's simply the message I show too). And maybe your manual (although not read by the user) mentions which kind of file you can select (so that's not different to my instructions). So that leaves just the setting/unsetting of the button as the slight difference between the two approaches.
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

They are both valid approaches. One validates the information before the button is clicked, the other after the button is clicked.

I would still say that the approach of only enabling the button when the information is valid is not as common. That doesn't make it any less valid. It is possibly the way to go going forward. But for a lot of "non techie" users of software their first reaction is often "why can't I click on that button!" - simply because they are not used to the button only being enabled if certain information is entered into a text area.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use FocusListener for ConfigOptions Panel