【发布时间】:2017-03-11 16:52:10
【问题描述】:
我在另一个 JPanel 中嵌套了一个 Jpanel。我想刷新其中一个 JPanel,而不刷新另一个。我有以下代码,我可以使用 repaint() 函数,但是它会更新所有的 JPanel,而不仅仅是我想要的(Time JPanel)。
我将如何只刷新 Time JPanel?保持天气 JPanel 不变? 我希望能够从外部线程执行此操作。
public class MainPanel extends JPanel{
public static JPanel TimePanel = new Time();
public static Weather WeatherPanel = new Weather();
public void paintComponent(Graphics g){
super.paintComponent(g);
this.setBackground(Color.BLACK);
this.setLayout(new FlowLayout(FlowLayout.LEADING, 0, 0));
TimePanel.setLocation(0, 0);
TimePanel.setSize(new Dimension(500, 300));
this.add(TimePanel);
WeatherPanel.setLocation(0,300);
WeatherPanel.setSize(new Dimension(100, 100));
this.add(WeatherPanel);
//repaint();//Just causes recursion
}
}
【问题讨论】:
标签: java swing jpanel refresh repaint