• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Disabling JButton until valid selection

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am working on the URLyBird assignment - but this is a more general question...
On my "Search Results" Page I have a JTable. I also have a JTextField, for the customer ID to be entered, and a JButton to "Book".
I'm looking to disable the JButton until:
- a row in the JTable has been selected
- and, an 8-Digit customer ID has been entered.
The JTable is setup so it cannot be edited, and only one row can be selected at a time.
I've had a play around with the API, but not getting anywhere.
Any hints would be much appreciated,
Neil
 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Neil

Originally posted by Neil Campbell:
Hi,
I am working on the URLyBird assignment - but this is a more general question...
On my "Search Results" Page I have a JTable. I also have a JTextField, for the customer ID to be entered, and a JButton to "Book".
I'm looking to disable the JButton until:
- a row in the JTable has been selected
- and, an 8-Digit customer ID has been entered.
The JTable is setup so it cannot be edited, and only one row can be selected at a time.
I've had a play around with the API, but not getting anywhere.
Any hints would be much appreciated,
Neil


One way of doing is you disable the button when you show results using setEnable(false) at the beginning. Later when the events you want occur, then in those respective event handler methods(like item selection handler method for table), enable the button using setEnabled(true).
This is one approach. Good Luck.
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a nice detail. To what level should we put these details in our program?
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The extent to which you should put in "nice features" like disabling the edit button if no record is highlighted is a judgement call. However, I think its a good idea to make sure you put in enough "features" to make sure the user can't crash your program simply by clicking a button.
 
Author
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Anthony. I think it is important to take care of those kinds of details, as you would on a real system. I started to think of my project as a sort of code repository that I could go to later when I need some bit of functionality.
 
Eben Hewitt
Author
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More specifically, if you are looking to enable the button in the way Satish describes, check out ListSelectionListener to determine if the user has picked a row.
 
reply
    Bookmark Topic Watch Topic
  • New Topic