Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ActionListener thing

Posted on 2004-09-07
7
Medium Priority
?
247 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
ID: 11995479
Instead of making those vars final, try making them as member variables of the outer class.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11995483
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
ID: 11995504
and check that temp contains the data you expect it to.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 92

Expert Comment

by:objects
ID: 11995517
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
ID: 11995522
I cannot do anything to the code beside adding the listeners for three buttons. :(
0
 
LVL 6

Expert Comment

by:expertmb
ID: 11995528
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 80 total points
ID: 11995891
>>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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

926 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