Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ActionListener thing

Posted on 2004-09-07
7
Medium Priority
?
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

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…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.
Suggested Courses

715 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