Solved

ActionListener thing

Posted on 2004-09-07
7
235 Views
Last Modified: 2010-03-31
I have: a frame called transcriptFrame which contains three buttons: getTranscriptNames, loadTranscript and cancel.

When the user clicks on loadTranscript, the JList should appear in new frame with the content showing the array of string, but my problem is, it doesnt show up:


Transcripts.addActionListener(new ActionListener()
           {
                 public void actionPerformed(ActionEvent e)
                {
                     final JFrame transcriptFrame = new JFrame("Load Transcripts");
                     final JButton getTranscriptNames = new JButton("Update Transcript List");
                     final JList transcripts = new JList();
                     final JButton loadTranscript = new JButton("Load Transcript");
                     final JButton cancel = new JButton("Cancel");
   
                     transcriptFrame.getContentPane().setLayout(new GridBagLayout());
   
                     transcriptFrame.getContentPane().add(transcripts, constraints_start);
                     transcriptFrame.getContentPane().add(getTranscriptNames, constraints_end);
                     transcriptFrame.getContentPane().add(loadTranscript, constraints_start);
                     transcriptFrame.getContentPane().add(cancel, constraints_end);
   
                     transcriptFrame.setVisible(true);
                     fixUpSize(transcriptFrame);
                     transcriptFrame.show();
   
                     getTranscriptNames.addActionListener(new ActionListener()
                     {
                           public void actionPerformed(ActionEvent e1)
                           {
                                 
                                 
                           }
                       });
   
                    loadTranscript.addActionListener(new ActionListener() {
                           public void actionPerformed(ActionEvent e1)
                           {
                                 
                                 try
                                        {
                                     transcripts.setListData(temp); // temp is an array of string
                                     transcriptFrame.setVisible(true);
                                  }
                                 catch (Exception e3)
                                  {
                                        System.out.println("Trouble: " + e3);
                                  }
                                 
                           }
                       });
   
                     cancel.addActionListener(new ActionListener() {
                           public void actionPerformed(ActionEvent e1)
                           {
                             transcriptFrame.setVisible(false);
                             transcriptFrame.dispose();
                           }
                       });
                 }
               });
   
0
Comment
Question by:jtcy
7 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
Instead of making those vars final, try making them as member variables of the outer class.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
You shouldn't create these components in the event handler. Create them first in your ctor and then all you need to do is

if (e.getSource() == loadTranscripts) {
    transcriptFrame.setVisible(true);
}
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
and check that temp contains the data you expect it to.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 92

Expert Comment

by:objects
Comment Utility
Also check your layout that the list is actually being displayed.

you may also want to include your list in a scroll pane:

 transcriptFrame.getContentPane().add(new JScrollPane(transcripts), constraints_start);
0
 

Author Comment

by:jtcy
Comment Utility
I cannot do anything to the code beside adding the listeners for three buttons. :(
0
 
LVL 6

Expert Comment

by:expertmb
Comment Utility
declare them as class varaibels. so that you can use them within the class as well as outside the class(instance varable)s
0
 
LVL 6

Accepted Solution

by:
expertmb earned 20 total points
Comment Utility
>>transcripts.setListData(temp); // temp is an array of string
>>transcriptFrame.setVisible(true);
you are displaying the list on same frame.

>>When the user clicks on loadTranscript, the JList should appear in new frame with the content showing the array of string,
hmmmmm you want to open in frame, then create new frame in
loadTranscript.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e1)
                        {
  JFrame fr = new JFrame();
  fr.setSize(400,400);
  fr.getContentPane().add(list);
  fr.setVisible(true);
});
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now