jtcy
asked on
ActionListener thing
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.addActionListe ner(new ActionListener()
{
public void actionPerformed(ActionEven t 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.getContent Pane().set Layout(new GridBagLayout());
transcriptFrame.getContent Pane().add (transcrip ts, constraints_start);
transcriptFrame.getContent Pane().add (getTransc riptNames, constraints_end);
transcriptFrame.getContent Pane().add (loadTrans cript, constraints_start);
transcriptFrame.getContent Pane().add (cancel, constraints_end);
transcriptFrame.setVisible (true);
fixUpSize(transcriptFrame) ;
transcriptFrame.show();
getTranscriptNames.addActi onListener (new ActionListener()
{
public void actionPerformed(ActionEven t e1)
{
}
});
loadTranscript.addActionLi stener(new ActionListener() {
public void actionPerformed(ActionEven t e1)
{
try
{
transcripts.setListData(te mp); // temp is an array of string
transcriptFrame.setVisible (true);
}
catch (Exception e3)
{
System.out.println("Troubl e: " + e3);
}
}
});
cancel.addActionListener(n ew ActionListener() {
public void actionPerformed(ActionEven t e1)
{
transcriptFrame.setVisible (false);
transcriptFrame.dispose();
}
});
}
});
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.addActionListe
{
public void actionPerformed(ActionEven
{
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.getContent
transcriptFrame.getContent
transcriptFrame.getContent
transcriptFrame.getContent
transcriptFrame.getContent
transcriptFrame.setVisible
fixUpSize(transcriptFrame)
transcriptFrame.show();
getTranscriptNames.addActi
{
public void actionPerformed(ActionEven
{
}
});
loadTranscript.addActionLi
public void actionPerformed(ActionEven
{
try
{
transcripts.setListData(te
transcriptFrame.setVisible
}
catch (Exception e3)
{
System.out.println("Troubl
}
}
});
cancel.addActionListener(n
public void actionPerformed(ActionEven
{
transcriptFrame.setVisible
transcriptFrame.dispose();
}
});
}
});
Instead of making those vars final, try making them as member variables of the outer class.
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);
}
if (e.getSource() == loadTranscripts) {
transcriptFrame.setVisible
}
and check that temp contains the data you expect it to.
Also check your layout that the list is actually being displayed.
you may also want to include your list in a scroll pane:
transcriptFrame.getContent Pane().add (new JScrollPane(transcripts), constraints_start);
you may also want to include your list in a scroll pane:
transcriptFrame.getContent
ASKER
I cannot do anything to the code beside adding the listeners for three buttons. :(
declare them as class varaibels. so that you can use them within the class as well as outside the class(instance varable)s
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.