मुझे लगता है कि जैसे एक कोड है:repaint() तुरंत "पुनः पेंट" नहीं करता है?
// In MyPanel.java
public void paintComponent(Graphics g)
{
super.paintComponent(g);
// Draw something
mypanel_count++;
}
// In Test.java
public void testLargeData()
{
while (notDone)
{
panel.repaint();
// do huge work
test_count++;
System.out.println("Test_count: " + test_count + ", MyPanel_count: " + mypanel_count);
}
}
// Output !!!
Test_count: 752, MyPanel_count: 23
Test_count: 753, MyPanel_count: 23
Test_count: 754, MyPanel_count: 23
Test_count: 755, MyPanel_count: 24
लेकिन जब मैं panel.paintComponent(panel.getGraphics())
को panel.repaint()
बदलने के लिए, बाहर सही है:
Test_count: 752, MyPanel_count: 752 Test_count: 753, MyPanel_count: 753 Test_count: 754, MyPanel_count: 754 Test_count: 755, MyPanel_count: 755
क्यों? paintComponent
विधि काम करता है, लेकिन कभी-कभी यह अंधा होता है, इसलिए मैं इसका उपयोग नहीं करना चाहता हूं। कोई मुझे कुछ सुझाव दे सकता है? धन्यवाद!
http://stackoverflow.com/questions/9389187/difference-between-paint-paintcomponent-and-paintcomponents-in-swing। – Raghunandan
@ रघुनाथन: आपके उत्तर के लिए धन्यवाद, लेकिन यह मेरी परेशानी नहीं है। –
आपने कोशिश की [JComponent.html # पेंट तुरंत (int, int, int, int)] (http://docs.oracle.com/javase/6/docs/api/javax/swing/JComponent.html#paintImmediately%28int ,% 20int,% 20int,% 20int% 29) – mKorbel