안녕이라고하지 다시 칠 나는 다음과 같은 코드 패키지 com.vf.zepto.view있다; 는 내가 검색 좀 내 paintComp 방법 밤은이 <p></p>을 호출되는 이유를 파악 할 수
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import javax.imageio.ImageIO;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import com.vf.zepto.view.interfaces.ProcessorPanel;
public class CountryDetailsPanel extends JPanel implements ProcessorPanel, Runnable {
private GridBagConstraints c = new GridBagConstraints();
private String countryName;
private Properties prop = new Properties();
private BufferedImage image;
public CountryDetailsPanel() {
try {
prop.load(new FileInputStream("country.props"));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//this.setLayout(new GridBagLayout());
c.gridx = 0;
c.gridy = 0;
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(5, 5, 5, 5);
this.setPreferredSize(new Dimension(200, 200));
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
try {
if(countryName != null) {
String asset = prop.getProperty(countryName+".flag");
if(!asset.equals(null)) {
image = ImageIO.read(new File(asset));
g.drawImage(image, 0, 0, null);
}
}
}
catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void updateDetails(Object o) {
countryName = (String)o;
SwingUtilities.invokeLater(this);
}
@Override
public void run() {
this.repaint();
}
}
및
this.repaint()
를 호출 할 때
paintComponent
메서드가 호출하지만 사랑도 돈이 밤은 될 것으로 기대합니다.
문제가 아니지만 EDT를 사용하도록 강요했습니다.
어떤 아이디어가 있습니까?
1 ** 사랑도 돈을 밤은을 위해 **. 문제의 이미지가 정확히 무엇입니까? –
paint가 paintComponent를 호출해야하는 것처럼 보입니다. http://www.leepoint.net/notes-java/GUI-lowlevel/graphics/15who-calls-paintcomponent.html 도움이 될 수 있습니다. –