Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Jcombobox

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

Im new to the forum i have been programming on and off for 3 years now i wouldnt call myself a great programmer in the slightest however im making a complex program atm which i hope you can all help me with if i need any help

right now ive just made 2 little static combo boxes with Hour & Minute when i try and print out the selection of either hour and minute it keeps doubling up for no reason :\

 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Run your code through a debugger (or put some System.out.println calls in your code) and see how often your itemStateChanged methods are called.
Then see what value ie.getStateChange() returns for each of those calls.
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

The recommended way of listening to JComboBox events is using ActionListeners http://download.oracle.com/javase/tutorial/uiswing/components/combobox.html#listeners
 
sean beacham
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:Welcome to the Ranch.

The recommended way of listening to JComboBox events is using ActionListeners http://download.oracle.com/javase/tutorial/uiswing/components/combobox.html#listeners



i think when i highlight when the itemlistener and then click off it jotted it down twice soon as i changed it to an actionlistner it works perfectly.

many thanks
 
Maneesh Godbole
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are welcome.

Actually it is logical. If you had checked what Joanne suggested you would have noticed one event for deselection and another for selection. A similar pitfall is for a JList when you use a ListSelectionListener. When using it, one should use the ListSelectionEvent#getValueIsAdjusting()
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic