Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7818327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:32:36+00:00 2026-06-02T06:32:36+00:00

import javax.swing.*; import javax.swing.event.*; public class NewGUIStuff{ public static void main(String args[]){ NewGUIStuff gui

  • 0
import javax.swing.*;
import javax.swing.event.*;

public class NewGUIStuff{
    public static void main(String args[]){
        NewGUIStuff gui = new NewGUIStuff();
        gui.go();
    }

    class handlesListListeners implements  ListSelectionListener{
        public void valueChanged(ListSelectionEvent lse){
            list.setVisibleRowCount(4);
        }
    }
    public void valueChanged(ListSelectionEvent lse){

    }
    public void go(){
        JFrame frame = new JFrame();
        JPanel panel = new JPanel();
        JList list;

        String[] aList = {"alpha","beta","gamma","delta","epsilon","zeta","eta","theta"};
        list = new JList(aList);
        list.addListSelectionListener(new handlesListListeners());
        JScrollPane scroller = new JScrollPane(list);
        scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        frame.setContentPane(scroller);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300,300);
        frame.setVisible(true);
    }
}

So my question here is if inner classes can see their outer classes variables and objects, why can’t the inner-class handlesListListeners see the list object I made in NewGUIStuff outer class?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:32:37+00:00Added an answer on June 2, 2026 at 6:32 am

    Non-static inner classes can see the outer class instance variables and those local variables they were enclosed around (think closures) if those were declared final (in case of anonymous inner classes). Those non-static inner classes have an implicit reference to the outer this inserted by the compiler and that’s how they see the member variables of the outer class. The final local variables you enclose your anonymous class around will be implicitly passed into the a constructor that the compiler will generate for you and stored in the final member fields of the inner class itself.

    In your case I see you expect to see a local variable defined in a whole different lexical context, the one your inner class has no knowledge about. Convert it into the outer class member variable and your inner class will see it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

//calling class import javax.swing.JFrame; class jcheckkbox { public static void main(String args[]) { jRadio
Here is the code: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class TestGrid {
package test; import java.awt.*; import java.awt.event.*; import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; import javax.swing.*; public class
Here is my code: import javax.swing.*; import java.awt.*; public class PanelModel { public static
import java.awt.*; import java.awt.image.ImageObserver; import javax.swing.*; public class CharacterMove { CharacterCollision CharacterCollision; public static
import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; public class Sheet extends JFrame{ private String[] line
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class twobuttons { int x=70; int y=70;
import java.awt.event.*; import java.io.File; import javax.swing.*; public class Launch extends JFrame implements ActionListener {
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; public class
import javax.swing.*; import javax.swing.text.DateFormatter; import java.awt.*; import java.awt.event.*; import java.text.SimpleDateFormat; import java.util.GregorianCalendar; public class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.