5 Replies - 1100 Views - Last Post: 01 October 2010 - 08:42 AM Rate Topic: -----

#1 sahildave1991   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 45
  • Joined: 18-September 10

Activating a Spinner after a particular item is selected from the Comb

Posted 01 October 2010 - 07:59 AM

Hey guys, i have a problem which i am facing from 2 3 days...i am making a tutorial on green buildings in java...i have build the core things, layout etc in NetBeans, but i am back to eclipse for some programming stuff...

My Problem

i want to 'activate' a spinner when a particular item from an adjacent dropbox (ComboBox) is selected...then the person would select a no. which i would you use further...

for eg. : i have a combobox with items "100 watt", "200 watt", "300 watt".
i want that when user select 100 and 200 watt, the spinner should not be activated (he cannot change the value of the spinner), as soon as he selects 300 watt, the spinner is activated and the person can now select any value.

My Question

how should i begin ? which event should i use, or any other suggestions....

Is This A Good Question/Topic? 0
  • +

Replies To: Activating a Spinner after a particular item is selected from the Comb

#2 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12333
  • View blog
  • Posts: 45,441
  • Joined: 27-December 08

Re: Activating a Spinner after a particular item is selected from the Comb

Posted 01 October 2010 - 08:15 AM

Take a look at using ActionListener to detect a change in value from the JComboBox.

Also, please don't use your other threads to direct people to your new threads. :)
Was This Post Helpful? 0
  • +
  • -

#3 guido-granobles   User is offline

  • D.I.C Addict
  • member icon

Reputation: 171
  • View blog
  • Posts: 617
  • Joined: 02-December 09

Re: Activating a Spinner after a particular item is selected from the Comb

Posted 01 October 2010 - 08:15 AM

Your class must implement the itemListener interface:
myJcombo.addItemListener(this)
ItemListener itemListener = new ItemListener() {
      public void itemStateChanged(ItemEvent itemEvent) {
        //check what item was selectd... disabled the spinner.
      }
};


This post has been edited by guidojavier: 01 October 2010 - 08:18 AM

Was This Post Helpful? 0
  • +
  • -

#4 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2965
  • View blog
  • Posts: 11,222
  • Joined: 15-July 08

Re: Activating a Spinner after a particular item is selected from the Comb

Posted 01 October 2010 - 08:16 AM

You can add an actionListener to the 100 and 200 and 300 Combobox items and then use JComponent's setEnabled() method to activate or deactivate the spinner.
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12333
  • View blog
  • Posts: 45,441
  • Joined: 27-December 08

Re: Activating a Spinner after a particular item is selected from the Comb

Posted 01 October 2010 - 08:21 AM

@: An ItemEvent is fired each time an element is de-selected, and each time an element is selected. ActionEvents are only fired when an element is selected in the JComboBox.
Was This Post Helpful? 1
  • +
  • -

#6 guido-granobles   User is offline

  • D.I.C Addict
  • member icon

Reputation: 171
  • View blog
  • Posts: 617
  • Joined: 02-December 09

Re: Activating a Spinner after a particular item is selected from the Comb

Posted 01 October 2010 - 08:42 AM

View Postmacosxnerd101, on 01 October 2010 - 02:21 PM, said:

@: An ItemEvent is fired each time an element is de-selected, and each time an element is selected. ActionEvents are only fired when an element is selected in the JComboBox.

macosxnerd101 you are absolutely right. It is just that I took this code from one method that I have and I need to know what was the previous selected item. So yes ActionListener is what he needs. :smile2:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1