0
getImage
을 사용하여 파일을 읽고 저장 한 다음이 이미지를 jpanels의 배경으로 설정합니다. 그러나 애플릿을 처음로드하면 이미지가 표시되지 않습니다. 크기를 조정하거나 위아래로 스크롤하면 이미지가 나타납니다. 문제가 무엇입니까?JPanel의 이미지가 즉시 표시되지 않습니다.
@Override
public void init(){
setSize(800, 600);
setLayout(new FlowLayout());
setup();
box1.setText(texts[0]);
box2.setText(texts[1]);
box3.setText(texts[2]);
box4.setText(texts[3]);
add(box1);
add(box2);
add(box3);
add(box4);
add(testPanel);
add(localPanel);
add(background2);
}
public void setup(){
box1 = new JTextArea();
box2 = new JTextArea();
box3 = new JTextArea();
box4 = new JTextArea();
box1.setText(texts[0]);
box2.setText(texts[1]);
box3.setText(texts[2]);
box4.setText(texts[3]);
//*********** this loads immediately **********//
Image back2 = getImage(getDocumentBase(), "blank_blue.png");
background2 = new JLabel(new ImageIcon(back2));
panelBack = getImage(getDocumentBase(), "CardBar.png");
localPanel = new JPanel(){
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(panelBack, 0, 0, null);
}
};
localPanel.setPreferredSize(new Dimension(100, 400));
}
게시 된 코드에 문제의 근원이 표시되지 않습니다. GUI를 렌더링하고 GUI에 컨테이너의 유효성을 다시 확인하고 다시 표시하지 않으면 GUI에 구성 요소를 추가하는 것으로 의심되지만 현재는 추측 할 수 있습니다. 더 많은 코드를 게시해야합니다. –
@HovercraftFullOfEels 코드를 업데이트했습니다. – rasen58