?
Solved

Getting out a variable from an inner class - JAVA GUI

Posted on 2004-11-22
3
Medium Priority
?
195 Views
Last Modified: 2010-03-31
I have a JList list:

When I add a listener

  private void setUp() throws Exception
  {
   ...
      list.addListSelectionListener(new ListSelectionListener() {
         public void valueChanged(ListSelectionEvent evt) {
                  JList lst = (JList)evt.getSource();
                  String selectedValue = (String) lst.getSelectedValue();
                      ...
         }
      });

How do I get out/return the selectedValue string so that I can use it in the regular outer method?
0
Comment
Question by:bcsmess
  • 2
3 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12650050
just call your outer method

     list.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
               JList lst = (JList)evt.getSource();
               String selectedValue = (String) lst.getSelectedValue();
               outerMethod(selectedValue);
        }
     });

0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 12650057
or store the value in a member variable if you need to use it later

     list.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
               JList lst = (JList)evt.getSource();
               member = (String) lst.getSelectedValue();
        }
     });
0
 
LVL 8

Expert Comment

by:kiranhk
ID: 12650080

>>>>> or store the value in a member variable if you need to use it later
that is what i posted in the other thread


http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21216458.html
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month16 days, 7 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question