Results 1 to 13 of 13
Thread: choice
- 09-23-2011, 12:12 PM #1
Member
- Join Date
- Aug 2011
- Posts
- 60
- Rep Power
- 0
choice
Java Code:public void x() { Choice c1 = new Choice(); Choice c = new Choice(); //filling c with items c.addItem(name); ... //then c.addItemListener(new ItemListener(){ public void itemStateChanged(ItemEvent e){ //filling de c1 c1.addItem(..) } }); JButton button; button.addActionListener(new ButtonBus(c.getSelectedItem(),c1.getSelectedItem())); }
how could i have the selected item
please help me
- 09-23-2011, 01:51 PM #2
Re: choice
What does getSelectedItem return if there are no selections?
- 09-23-2011, 03:02 PM #3
Member
- Join Date
- Aug 2011
- Posts
- 60
- Rep Power
- 0
Re: choice
so how do get the showed item??
- 09-23-2011, 03:03 PM #4
Re: choice
Does the Choice class have a get... method you could use?
- 09-23-2011, 03:59 PM #5
Member
- Join Date
- Aug 2011
- Posts
- 60
- Rep Power
- 0
Re: choice
tha's me how is asking does there any method that help me to have the showed item in the Choice Component
- 09-23-2011, 04:04 PM #6
Re: choice
how is asking does there any method that help me
Have you done that?
Which of the get... methods do you think would be useful?
If you have any specific questions about any of the get... methods, ask them here.
- 09-23-2011, 04:24 PM #7
Member
- Join Date
- Aug 2011
- Posts
- 60
- Rep Power
- 0
Re: choice
i read Choice api but i didn't have any method that help to have the showed item
- 09-23-2011, 05:13 PM #8
Re: choice
If the Choice class does not have any methods to get items from its menu list then I don't think you can do it.
- 09-23-2011, 05:19 PM #9
Re: choice
If you are not sure which get.... method to use. Try using several of them and print out the values that they return.
Then look at what is printed to see which method returned what you want.
- 09-23-2011, 05:48 PM #10
Member
- Join Date
- Aug 2011
- Posts
- 60
- Rep Power
- 0
Re: choice
my problem is that when i print result into "itemstatechange" bloc of c1.getSelectedItem is ok
but out this bloc i have null as result
so how could i have the selected item out "itemstatechange" bloc
- 09-23-2011, 05:55 PM #11
Re: choice
when i print result into "itemstatechange" bloc of c1.getSelectedItem is ok
but out this bloc i have null as result
This problem sounds like you have two variables with the same name at different scopes.
You assign the local variable a value which goes away when you exit a method. The variable at the other level of scope does not get any value and stays null.
- 09-24-2011, 10:11 AM #12
Member
- Join Date
- Aug 2011
- Posts
- 60
- Rep Power
- 0
Re: choice
Java Code:public void x() { String x=""; Choice c1 = new C Choice(); Choice c = new Choice(); //filling c with items c.addItem(name); ... //then c.addItemListener(new ItemListener(){ public void itemStateChanged(ItemEvent e){ //filling de c1 c1.addItem(..) x=c1.getSelectedItem(); System.out.println("x1="+x); } }); System.out.println("x2="+x); }
x1="the selected item"
x2=null
my question is how to get the value of xthe selected item of c1(Choice) out of itemstatechange
- 09-24-2011, 02:00 PM #13
Similar Threads
-
LayoutManager Best Choice
By 67726e in forum AWT / SwingReplies: 2Last Post: 11-10-2010, 02:59 AM -
Syntax for choice box(combo box)
By NickkicN in forum New To JavaReplies: 2Last Post: 08-14-2008, 10:26 PM -
Need help with T/F and Multiple Choice
By sayso36 in forum Advanced JavaReplies: 0Last Post: 03-12-2008, 04:39 PM -
Using java.awt.Choice
By Java Tip in forum Java TipReplies: 0Last Post: 01-02-2008, 06:33 PM
Bookmarks