0

クラスから呼び出したときに特定のパネルの文字列を更新するメソッドを作成しようとしています。descriptionPanel は静的パネルで、description はクラスをインスタンス化するときに定義する静的文字列です。これを定義しているクラスには多くのパネルがあるため、使用する必要があるパネルを指定するには、descriptionPanel.paintComponent を実行します。これは、私が常に更新するパネルです。このコードが機能しないことはわかっています。最初の間違いは、メソッドを定義できないことですが、これは、私が何をしようとしているのかを示すためのものです。

void updateDescriptionPanel(String dataToAppend){

    description = description.concat(dataToAppend);
    descriptionPanel.paintComponent(Graphics g){
            g.drawString(description, 10, 11);
    }
    descriptionPanel.repaint();

}  

私はいくつかのことを試しました

void paintComponent(Graphics g){
g.drawString(description, 10, 11);
}

void updateDescriptionPanel(String dataToAppend){

    description = description.concat(dataToAppend);
    Graphics g=null;
    paintComponent(g);
    descriptionPanel.repaint();

}

しかし、ここではどのパネルを更新するかわかりません。

ここに画像の説明を入力

public class Application_GUI {

static String description  = "" ;
    static JPanel descriptionPanel;
//other initializations

void paintComponent(Graphics g){

    g.drawString(description, 10, 11);
}
public String[] getRepositoryList(ArrayList<ResourceListObject> imagerepositorylist)
// method which uses another class to get that List
// If I get the list I print a string 
// Connection successful to the description Panel

void updateDescriptionPanel(String dataToAppend){

    description = description.concat(dataToAppend);
    Graphics g=null;
    paintComponent(g);
    descriptionPanel.repaint();
}


final JPanel panel = new JPanel();    

JPanel panel_2 = new JPanel();
//scrollBar initialization    

descriptionPanel = new JPanel();
final JComboBox comboBox = new JComboBox();
//get comboBoxOptions by making a connection and then adding it
//ActionListener inner class for the comboBox

これは、すべてのかなりのアクションリスナーです。アクション リスナーには、自分自身で処理を行うものと、他のクラスを使用して処理を行うものがあります。したがって、私がやりたいことは、すべてのアクション リスナーから descriptionPanel を更新できるようにすることです。つまり、アクション リスナーが特定の操作を実行するために呼び出しを行うとき、特に大きなタスクを実行している swingWorker が完了したときに SwingWorker を実行できるようにする必要があります。 descriptionPanel を更新します。

4

0 に答える 0