したがって、私のコードには基本的にJPanel
いくつかのテキストフィールドと がありJButton
、ユーザーがボタンをクリックするとボタンリスナーに移動し、テキストフィールドからデータを取得して処理し、JLabels
別の非表示に追加するものを作成しますJPanel
。次に、最初の JPanel を非表示にし、2 番目のパネルを表示して、生成した「結果」を表示します。
これはすべて機能しますが、問題は、プログラムがテキストフィールドから取得したデータを処理しているときに、プログラムのJButton
内容を変更したいというevent.getSource().setText()
ことです.コンソールに出力することによって)、変更されたテキストでボタンを更新していません。
この後、すべての形式の再検証と再描画と検証も試しましたが、どれも機能しませんでした。何か案は?ありがとう!
//entryPanel is the first panel, and picksPanel is the second panel
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
((JButton)event.getSource()).setText("Thinking...");
revalidate();
repaint();
try
{
CriticPick picks = new CriticPick(cityfield.getText(),statefield.getText());
LinkedList<Movie> pickslist = picks.getList();
glayout.setRows(pickslist.size()+2+thepicks.movnum);
picksPanel.add(new JLabel("The Results:"));
//In my actual code I do a bunch of processing and looping that results in jlabels being added to picksPanel
for (int i=0;i<pickslist.size();i++)
{
JLabel label = new JLabel(pickslist.get(i).title);
picksPanel.add(label);
}
}
catch (Exception exc)
{
System.out.println(exc);
}
entryPanel.setVisible(false);
picksPanel.setVisible(true);
}});
guiFrame.add(entryPanel);
guiFrame.add(picksPanel);
guiFrame.setLayout(new FlowLayout(FlowLayout.LEFT));
guiFrame.setVisible(true);
}