java更新Jpanel组件

java更新Jpanel组件,java,swing,jpanel,validation,repaint,Java,Swing,Jpanel,Validation,Repaint,我在我的Gui Builder JFram Class a中使用一个Custome jPanel,我面临的问题是当我在JFrame中单击按钮时更新我的jPanel中的组件(标签)。以下是Gui Builder JFrame ClassA中的按钮:它更改Jpl的颜色并删除所有标签,但不更新新标签 private void btnShowActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling co

我在我的Gui Builder JFram Class a中使用一个Custome jPanel,我面临的问题是当我在JFrame中单击按钮时更新我的jPanel中的组件(标签)。以下是Gui Builder JFrame ClassA中的按钮:它更改Jpl的颜色并删除所有标签,但不更新新标签

private void btnShowActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:

            Random randomGenerator = new Random();
            for (int idx = 1; idx <= 10; ++idx) {
                q = randomGenerator.nextInt(100);
            }
            jpl1.removeAll();
            new Jpl().printMe(ClassA.q);
            jpl1.revalidate();
            jpl1.setBackground(Color.BLUE);
            jpl1.repaint();
}
private void btnShowActionPerformed(java.awt.event.ActionEvent evt){
//TODO在此处添加您的处理代码:
Random randomGenerator=新的Random();
对于(int idx=1;idx您正在Jpl的新实例上调用printMe(),请尝试:

private void btnShowActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:

            Random randomGenerator = new Random();
            for (int idx = 1; idx <= 10; ++idx) {
                q = randomGenerator.nextInt(100);
            }
            jpl1.removeAll();
            jpl1.printMe(ClassA.q); // HERE - REMOVED new and using jpl1 instance
            jpl1.setBackground(Color.BLUE);
            jpl1.revalidate();
            jpl1.repaint();
}
private void btnShowActionPerformed(java.awt.event.ActionEvent evt){
//TODO在此处添加您的处理代码:
Random randomGenerator=新的Random();

对于(int-idx=1;idx它可以工作!!谢谢
private void btnShowActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:

            Random randomGenerator = new Random();
            for (int idx = 1; idx <= 10; ++idx) {
                q = randomGenerator.nextInt(100);
            }
            jpl1.removeAll();
            jpl1.printMe(ClassA.q); // HERE - REMOVED new and using jpl1 instance
            jpl1.setBackground(Color.BLUE);
            jpl1.revalidate();
            jpl1.repaint();
}