我正在尝试创建一个方法,当我从任何类调用时,它会更新特定面板上的字符串。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,它应该能够更新描述面板。