我回來了一個有關Java的圖形通過擺問題...我想在一個JFrame畫一些東西,這裏是代碼:重繪永遠不會到達paintComponent();
PaintUtil級:
public class PaintUtil extends JPanel{
public PaintUtil(){
this.setFocusable(true);
this.requestFocus();
}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
System.out.println("Repainted");
g.drawstuff...
}
}
Main-等級:
public static PaintUtil util = new PaintUtil();
JFrame frame = new JFrame();
frame.setSize(500,600);
frame.setRezisable(false);
frame.add(util);
frame.setDefaultCloseOperation(3);
frame.getContentPane().setColor(Color.BLACK);
setup(); //This add some buttons
frame.setVisible(true);
util.repaint(); //not working
util.paintComponent(frame.getGraphics()); //works
你們能幫我嗎?
什麼'PaintUtil'擴展? –
PaintUtil擴展JPanel – Caipi
您的組件實際上是否在屏幕上? – khelwood